Spring Boot导出的jar无法正常工作(org.springframework.beans.factory.BeanCreationException:创建名为'entityManagerFactory'的bean时出错)

时间:2015-08-23 16:23:41

标签: spring hibernate jpa jar spring-boot

我们一直致力于在(Intellij)ide中运行它时工作正常的项目。但是当我们将spring boot项目导出为jar文件时,它就不再有效了

    21:33:06.495 [main] INFO  demo.TrainsFromApplication - Starting TrainsFromApplication on macbook-pro with PID 1955 (/Users/sauravskumar/IdeaProjects/TrainsFrom/out/artifacts/TrainsFrom_jar/TrainsFrom.jar started by sauravskumar in /Users/sauravskumar/IdeaProjects/TrainsFrom/out/artifacts/TrainsFrom_jar)
21:33:06.687 [main] INFO  o.s.b.c.e.AnnotationConfigEmbeddedWebApplicationContext - Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@23282c25: startup date [Sun Aug 23 21:33:06 IST 2015]; root of context hierarchy
21:33:09.528 [main] INFO  o.s.b.f.s.DefaultListableBeanFactory - Overriding bean definition for bean 'beanNameViewResolver' with a different definition: replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration$WhitelabelErrorViewConfiguration; factoryMethodName=beanNameViewResolver; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfigure/web/ErrorMvcAutoConfiguration$WhitelabelErrorViewConfiguration.class]] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter; factoryMethodName=beanNameViewResolver; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter.class]]
21:33:10.660 [main] INFO  o.h.validator.internal.util.Version - HV000001: Hibernate Validator 5.1.3.Final
21:33:10.941 [main] WARN  demo.TrainsFromApplication - No Spring profile configured, running with default configuration
21:33:10.941 [main] INFO  o.s.c.s.PostProcessorRegistrationDelegate$BeanPostProcessorChecker - Bean 'trainsFromApplication' of type [class demo.TrainsFromApplication$$EnhancerBySpringCGLIB$$e78db5e1] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
21:33:10.942 [main] INFO  o.s.d.n.config.Neo4jConfiguration - Initialising PersistenceExceptionTranslationPostProcessor
21:33:11.143 [main] INFO  o.s.c.s.PostProcessorRegistrationDelegate$BeanPostProcessorChecker - Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [class org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$5c0f18ac] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
21:33:12.005 [main] INFO  org.eclipse.jetty.util.log - Logging initialized @10510ms
21:33:12.376 [main] INFO  o.s.b.c.e.j.JettyEmbeddedServletContainerFactory - Server initialized with port: 8080
21:33:12.380 [main] INFO  org.eclipse.jetty.server.Server - jetty-9.2.11.v20150529
21:33:12.678 [main] INFO  application - Initializing Spring embedded WebApplicationContext
21:33:12.678 [main] INFO  o.s.web.context.ContextLoader - Root WebApplicationContext: initialization completed in 6046 ms
21:33:14.305 [main] INFO  o.s.b.c.e.ServletRegistrationBean - Mapping servlet: 'dispatcherServlet' to [/]
21:33:14.348 [main] INFO  o.s.b.c.e.FilterRegistrationBean - Mapping filter: 'characterEncodingFilter' to: [/*]
21:33:14.359 [main] INFO  o.s.b.c.e.FilterRegistrationBean - Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
21:33:14.360 [main] INFO  o.s.b.c.e.FilterRegistrationBean - Mapping filter: 'simpleCORSFilter' to: [/*]
21:33:14.361 [main] INFO  o.e.j.server.handler.ContextHandler - Started o.s.b.c.e.j.JettyEmbeddedWebAppContext@5c5d6175{/,null,AVAILABLE}
21:33:14.361 [main] INFO  org.eclipse.jetty.server.Server - Started @12866ms
21:33:15.233 [main] INFO  o.s.o.j.LocalContainerEntityManagerFactoryBean - Building JPA container EntityManagerFactory for persistence unit 'default'
21:33:15.302 [main] INFO  o.h.jpa.internal.util.LogHelper - HHH000204: Processing PersistenceUnitInfo [
    name: default
    ...]
21:33:15.558 [main] INFO  org.hibernate.Version - HHH000412: Hibernate Core {4.3.10.Final}
21:33:15.562 [main] INFO  org.hibernate.cfg.Environment - HHH000206: hibernate.properties not found
21:33:15.566 [main] INFO  org.hibernate.cfg.Environment - HHH000021: Bytecode provider name : javassist
21:33:15.637 [main] WARN  o.s.b.c.e.AnnotationConfigEmbeddedWebApplicationContext - Exception encountered during context initialization - cancelling refresh attempt
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: javax.persistence.spi.PersistenceUnitInfo.getValidationMode()Ljavax/persistence/ValidationMode;
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1578) ~[spring-beans-4.2.0.RC1.jar:4.2.0.RC1]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545) ~[spring-beans-4.2.0.RC1.jar:4.2.0.RC1]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[spring-beans-4.2.0.RC1.jar:4.2.0.RC1]
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304) ~[spring-beans-4.2.0.RC1.jar:4.2.0.RC1]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.2.0.RC1.jar:4.2.0.RC1]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300) ~[spring-beans-4.2.0.RC1.jar:4.2.0.RC1]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195) ~[spring-beans-4.2.0.RC1.jar:4.2.0.RC1]
    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1011) ~[spring-context-4.2.0.RC1.jar:4.2.0.RC1]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:802) ~[spring-context-4.2.0.RC1.jar:4.2.0.RC1]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:521) ~[spring-context-4.2.0.RC1.jar:4.2.0.RC1]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118) [spring-boot-1.3.0.M1.jar:1.3.0.M1]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:678) [spring-boot-1.3.0.M1.jar:1.3.0.M1]
    at org.springframework.boot.SpringApplication.doRun(SpringApplication.java:339) [spring-boot-1.3.0.M1.jar:1.3.0.M1]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:274) [spring-boot-1.3.0.M1.jar:1.3.0.M1]
    at demo.TrainsFromApplication.main(TrainsFromApplication.java:119) [TrainsFrom.jar:na]
Caused by: java.lang.NoSuchMethodError: javax.persistence.spi.PersistenceUnitInfo.getValidationMode()Ljavax/persistence/ValidationMode;
    at org.hibernate.jpa.boot.internal.PersistenceUnitInfoDescriptor.getValidationMode(PersistenceUnitInfoDescriptor.java:99) ~[hibernate-entitymanager-4.3.10.Final.jar:4.3.10.Final]
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.mergePropertySources(EntityManagerFactoryBuilderImpl.java:569) ~[hibernate-entitymanager-4.3.10.Final.jar:4.3.10.Final]
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<init>(EntityManagerFactoryBuilderImpl.java:214) ~[hibernate-entitymanager-4.3.10.Final.jar:4.3.10.Final]
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<init>(EntityManagerFactoryBuilderImpl.java:188) ~[hibernate-entitymanager-4.3.10.Final.jar:4.3.10.Final]
    at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:54) ~[spring-orm-4.2.0.RC1.jar:4.2.0.RC1]
    at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:343) ~[spring-orm-4.2.0.RC1.jar:4.2.0.RC1]
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:318) ~[spring-orm-4.2.0.RC1.jar:4.2.0.RC1]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637) ~[spring-beans-4.2.0.RC1.jar:4.2.0.RC1]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574) ~[spring-beans-4.2.0.RC1.jar:4.2.0.RC1]
    ... 14 common frames omitted
21:33:15.755 [main] INFO  o.e.j.server.handler.ContextHandler - Stopped o.s.b.c.e.j.JettyEmbeddedWebAppContext@5c5d6175{/,null,UNAVAILABLE}
21:33:15.758 [main] INFO  o.s.b.l.ClasspathLoggingApplicationListener - Application failed to start with classpath: [file:/Users/sauravskumar/IdeaProjects/TrainsFrom/out/artifacts/TrainsFrom_jar/TrainsFrom.jar]
21:33:15.758 [main] ERROR o.s.boot.SpringApplication - Application startup failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: javax.persistence.spi.PersistenceUnitInfo.getValidationMode()Ljavax/persistence/ValidationMode;
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1578) ~[spring-beans-4.2.0.RC1.jar:4.2.0.RC1]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545) ~[spring-beans-4.2.0.RC1.jar:4.2.0.RC1]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[spring-beans-4.2.0.RC1.jar:4.2.0.RC1]
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304) ~[spring-beans-4.2.0.RC1.jar:4.2.0.RC1]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.2.0.RC1.jar:4.2.0.RC1]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300) ~[spring-beans-4.2.0.RC1.jar:4.2.0.RC1]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195) ~[spring-beans-4.2.0.RC1.jar:4.2.0.RC1]
    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1011) ~[spring-context-4.2.0.RC1.jar:4.2.0.RC1]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:802) ~[spring-context-4.2.0.RC1.jar:4.2.0.RC1]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:521) ~[spring-context-4.2.0.RC1.jar:4.2.0.RC1]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118) ~[spring-boot-1.3.0.M1.jar:1.3.0.M1]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:678) ~[spring-boot-1.3.0.M1.jar:1.3.0.M1]
    at org.springframework.boot.SpringApplication.doRun(SpringApplication.java:339) ~[spring-boot-1.3.0.M1.jar:1.3.0.M1]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:274) ~[spring-boot-1.3.0.M1.jar:1.3.0.M1]
    at demo.TrainsFromApplication.main(TrainsFromApplication.java:119) [TrainsFrom.jar:na]
Caused by: java.lang.NoSuchMethodError: javax.persistence.spi.PersistenceUnitInfo.getValidationMode()Ljavax/persistence/ValidationMode;
    at org.hibernate.jpa.boot.internal.PersistenceUnitInfoDescriptor.getValidationMode(PersistenceUnitInfoDescriptor.java:99) ~[hibernate-entitymanager-4.3.10.Final.jar:4.3.10.Final]
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.mergePropertySources(EntityManagerFactoryBuilderImpl.java:569) ~[hibernate-entitymanager-4.3.10.Final.jar:4.3.10.Final]
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<init>(EntityManagerFactoryBuilderImpl.java:214) ~[hibernate-entitymanager-4.3.10.Final.jar:4.3.10.Final]
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<init>(EntityManagerFactoryBuilderImpl.java:188) ~[hibernate-entitymanager-4.3.10.Final.jar:4.3.10.Final]
    at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:54) ~[spring-orm-4.2.0.RC1.jar:4.2.0.RC1]
    at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:343) ~[spring-orm-4.2.0.RC1.jar:4.2.0.RC1]
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:318) ~[spring-orm-4.2.0.RC1.jar:4.2.0.RC1]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637) ~[spring-beans-4.2.0.RC1.jar:4.2.0.RC1]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574) ~[spring-beans-4.2.0.RC1.jar:4.2.0.RC1]
    ... 14 common frames omitted
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: javax.persistence.spi.PersistenceUnitInfo.getValidationMode()Ljavax/persistence/ValidationMode;
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1578)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1011)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:802)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:521)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:678)
    at org.springframework.boot.SpringApplication.doRun(SpringApplication.java:339)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:274)
    at demo.TrainsFromApplication.main(TrainsFromApplication.java:119)
Caused by: java.lang.NoSuchMethodError: javax.persistence.spi.PersistenceUnitInfo.getValidationMode()Ljavax/persistence/ValidationMode;
    at org.hibernate.jpa.boot.internal.PersistenceUnitInfoDescriptor.getValidationMode(PersistenceUnitInfoDescriptor.java:99)
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.mergePropertySources(EntityManagerFactoryBuilderImpl.java:569)
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<init>(EntityManagerFactoryBuilderImpl.java:214)
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<init>(EntityManagerFactoryBuilderImpl.java:188)
    at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:54)
    at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:343)
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:318)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)
    ... 14 more

pom.xml文件是: -

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

<groupId>org.test</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>trains_from</name>
<description>Demo project for Spring Boot</description>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.3.0.M1</version>
    <!--<version>1.3.0.M3</version>-->
    <!--<relativePath/> &lt;!&ndash; lookup parent from repository &ndash;&gt;-->
</parent>

<properties>
    <neo4j.version>2.2.4</neo4j.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <java.version>1.8</java.version>
    <!--<springdatacommons.version>1.11.0.RC1</springdatacommons.version>-->
    <springdatacommons.version>1.11.0.BUILD-SNAPSHOT</springdatacommons.version>
</properties>

<dependencies>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>

    <!--<dependency>-->
        <!--<groupId>redis.clients</groupId>-->
        <!--<artifactId>jedis</artifactId>-->
        <!--<version>2.7.2</version>-->
        <!--<type>jar</type>-->
        <!--<scope>compile</scope>-->
    <!--</dependency>-->
    <!--<dependency>-->
        <!--<groupId>org.springframework.boot</groupId>-->
        <!--<artifactId>spring-boot-starter-jdbc</artifactId>-->
    <!--</dependency>-->
    <!--<dependency>-->
        <!--<groupId>org.springframework.boot</groupId>-->
        <!--<artifactId>spring-boot-starter-redis</artifactId>-->
    <!--</dependency>-->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <!-- spring-data-neo4j -->
    <dependency>
        <groupId>org.neo4j</groupId>
        <artifactId>neo4j-ogm</artifactId>
        <version>1.1.1</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-commons</artifactId>
        <version>${springdatacommons.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-neo4j</artifactId>
        <version>4.0.0.RC1</version>
    </dependency>
    <!--<dependency>-->
        <!--<groupId>org.neo4j.app</groupId>-->
        <!--<artifactId>neo4j-server</artifactId>-->
        <!--<version>${neo4j.version}</version>-->
    <!--</dependency>-->
    <dependency>
        <groupId>com.voodoodyne.jackson.jsog</groupId>
        <artifactId>jackson-jsog</artifactId>
        <version>1.1</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <scope>runtime</scope>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <!--<dependency>-->
        <!--<groupId>org.springframework.data</groupId>-->
        <!--<artifactId>spring-data-neo4j</artifactId>-->
        <!--<version>4.0.0.BUILD-SNAPSHOT</version>-->
        <!--<type>test-jar</type>-->
    <!--</dependency>-->

    <!--REST-->
    <!--<dependency>-->
        <!--<groupId>org.json</groupId>-->
        <!--<artifactId>json</artifactId>-->
        <!--<version>20141113</version>-->
    <!--</dependency>-->
    <!--<dependency>-->
        <!--<groupId>com.googlecode.json-simple</groupId>-->
        <!--<artifactId>json-simple</artifactId>-->
        <!--<version>1.1.1</version>-->
    <!--</dependency>-->
    <!--<dependency>-->
        <!--<groupId>com.squareup.okhttp</groupId>-->
        <!--<artifactId>okhttp</artifactId>-->
        <!--<version>2.4.0</version>-->
    <!--</dependency>-->
    <dependency>
        <groupId>com.mashape.unirest</groupId>
        <artifactId>unirest-java</artifactId>
        <version>1.4.6</version>
    </dependency>
    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpclient</artifactId>
        <version>4.3.6</version>
    </dependency>
    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpasyncclient</artifactId>
        <version>4.0.2</version>
    </dependency>
    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpmime</artifactId>
        <version>4.3.6</version>
    </dependency>
    <dependency>
        <groupId>org.json</groupId>
        <artifactId>json</artifactId>
        <version>20141113</version>
    </dependency>

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.11</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
        <version>2.4</version>
        <scope>test</scope>
    </dependency>


    <dependency>
        <groupId>org.neo4j</groupId>
        <artifactId>neo4j-kernel</artifactId>
        <version>${neo4j.version}</version>
        <type>test-jar</type>
    </dependency>

    <dependency>
        <groupId>org.neo4j.app</groupId>
        <artifactId>neo4j-server</artifactId>
        <version>${neo4j.version}</version>
        <type>test-jar</type>
    </dependency>
    <dependency>
        <groupId>org.neo4j</groupId>
        <artifactId>neo4j-io</artifactId>
        <version>${neo4j.version}</version>
        <type>test-jar</type>
    </dependency>

</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <!--<configuration>-->
                <!--<mainClass>demo.TrainsFromApplication</mainClass>-->
            <!--</configuration>-->
        </plugin>
    </plugins>
</build>
<repositories>

    <repository>
        <id>spring-libs-snapshot</id>
        <name>Spring</name>
        <url>http://repo.spring.io/libs-snapshot</url>
    </repository>

    <repository>
        <id>spring-snapshots</id>
        <url>http://repo.spring.io/snapshot</url>
        <snapshots><enabled>true</enabled></snapshots>
    </repository>

    <repository>
        <id>spring-milestones</id>
        <url>http://repo.spring.io/milestone</url>
    </repository>

    <repository>
        <id>neo4j</id>
        <url>http://m2.neo4j.org/content/repositories/releases</url>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>

</repositories>

<pluginRepositories>

    <pluginRepository>
        <id>spring-snapshots</id>
        <url>http://repo.spring.io/snapshot</url>
    </pluginRepository>

    <pluginRepository>
        <id>spring-milestones</id>
        <url>http://repo.spring.io/milestone</url>
    </pluginRepository>

</pluginRepositories>

<!--<repositories>-->
    <!--<repository>-->
        <!--<id>spring-snapshots</id>-->
        <!--<name>Spring Snapshots</name>-->
        <!--<url>https://repo.spring.io/snapshot</url>-->
        <!--<snapshots>-->
            <!--<enabled>true</enabled>-->
        <!--</snapshots>-->
    <!--</repository>-->
    <!--<repository>-->
        <!--<id>spring-milestones</id>-->
        <!--<name>Spring Milestones</name>-->
        <!--<url>https://repo.spring.io/milestone</url>-->
        <!--<snapshots>-->
            <!--<enabled>false</enabled>-->
        <!--</snapshots>-->
    <!--</repository>-->
<!--</repositories>-->
<!--<pluginRepositories>-->
    <!--<pluginRepository>-->
        <!--<id>spring-snapshots</id>-->
        <!--<name>Spring Snapshots</name>-->
        <!--<url>https://repo.spring.io/snapshot</url>-->
        <!--<snapshots>-->
            <!--<enabled>true</enabled>-->
        <!--</snapshots>-->
    <!--</pluginRepository>-->
    <!--<pluginRepository>-->
        <!--<id>spring-milestones</id>-->
        <!--<name>Spring Milestones</name>-->
        <!--<url>https://repo.spring.io/milestone</url>-->
        <!--<snapshots>-->
            <!--<enabled>false</enabled>-->
        <!--</snapshots>-->
    <!--</pluginRepository>-->
<!--</pluginRepositories>-->

# application.properties file is


spring.datasource.url = jdbc:mysql://localhost:3306/trains_from_test


spring.datasource.username = root
spring.datasource.password =


spring.jpa.show-sql = true


spring.jpa.hibernate.ddl-auto = none


spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.ImprovedNamingStrategy


spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect

当我们更换

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.3.0.M1</version> 
</parent>

在pom.xml中

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.3.0.M2</version> 
</parent>

错误更改为: -

  macbook-pro:TrainsFrom_jar sauravskumar$ java -jar TrainsFrom.jar
Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/dao/support/PersistenceExceptionTranslator
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2693)
    at java.lang.Class.privateGetMethodRecursive(Class.java:3040)
    at java.lang.Class.getMethod0(Class.java:3010)
    at java.lang.Class.getMethod(Class.java:1776)
    at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
    at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException: org.springframework.dao.support.PersistenceExceptionTranslator
    at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 7 more

免责声明:我们也尝试了

  <properties>
            <neo4j.version>2.2.4</neo4j.version>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
            <java.version>1.8</java.version>
            <springdatacommons.version>1.11.0.RC1</springdatacommons.version>
            <!--<springdatacommons.version>1.11.0.BUILD-SNAPSHOT</springdatacommons.version>-->
        </properties>

但输出错误与第二个错误相同。提前谢谢!

1 个答案:

答案 0 :(得分:1)

您在类路径上有两个不同的JPA API jar。一个用于JPA 1.0,一个用于JPA 2.1。您需要从类路径中排除JPA 1.0 jar。从Maven的输出中,您可以看到它是spring-data-neo4j的依赖关系:

+- org.springframework.data:spring-data-neo4j:jar:4.0.0.RC1:compile
|  +- org.springframework:spring-context:jar:4.2.0.RC1:compile
|  +- org.springframework:spring-tx:jar:4.2.0.RC1:compile
|  \- javax.persistence:com.springsource.javax.persistence:jar:1.0.0:compile

您需要更新pom中的Spring Data Neo4J依赖项以排除JPA API:

<dependency>
    <groupId>org.springframework.data</groupId>
    <artifactId>spring-data-neo4j</artifactId>
    <version>4.0.0.RC1</version>
    <exclusions>
        <exclusion>
            <groupId>javax.persistence</groupId>
            <artifactId>com.springsource.javax.persistence</artifactId>
        </exclusion>
    <exclusion>
</dependency>