2016-11-21 55 views
0

我想在獨立碼頭上部署一個spring引導應用程序war文件。但是,當我開始的碼頭,我碰到這個錯誤java.lang.NoSuchMethodError:javax.persistence.JoinColumn.foreignKey()

Caused by: java.lang.NoSuchMethodError: javax.persistence.JoinColumn.foreignKey()Ljavax/persistence/ForeignKey; 
at org.hibernate.cfg.AnnotationBinder.bindManyToOne(AnnotationBinder.java:2909) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final] 
at org.hibernate.cfg.AnnotationBinder.bindOneToOne(AnnotationBinder.java:3086) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final] 
at org.hibernate.cfg.AnnotationBinder.processElementAnnotations(AnnotationBinder.java:1809) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final] 
at org.hibernate.cfg.AnnotationBinder.processIdPropertiesIfNotAlready(AnnotationBinder.java:911) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final] 
at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:738) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final] 
at org.hibernate.boot.model.source.internal.annotations.AnnotationMetadataSourceProcessorImpl.processEntityHierarchies(AnnotationMetadataSourceProcessorImpl.java:245) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final] 
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess$1.processEntityHierarchies(MetadataBuildingProcess.java:222) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final] 
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:265) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final] 
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:847) ~[hibernate-entitymanager-5.0.11.Final.jar:5.0.11.Final] 
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:874) ~[hibernate-entitymanager-5.0.11.Final.jar:5.0.11.Final] 
at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:60) ~[spring-orm-4.3.3.RELEASE.jar:4.3.3.RELEASE] 
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:353) ~[spring-orm-4.3.3.RELEASE.jar:4.3.3.RELEASE] 
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:373) ~[spring-orm-4.3.3.RELEASE.jar:4.3.3.RELEASE] 
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:362) ~[spring-orm-4.3.3.RELEASE.jar:4.3.3.RELEASE] 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1642) ~[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE] 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1579) ~[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE] 
... 60 common frames omitted 

這裏是我的pom.xml

<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/maven-v4_0_0.xsd"> 
<modelVersion>4.0.0</modelVersion> 
<groupId>com.example</groupId> 
<artifactId>configservice</artifactId> 
<packaging>war</packaging> 
<version>0.0.1-SNAPSHOT</version> 
<name>configservice Maven Webapp</name> 
<url>http://maven.apache.org</url> 
<parent> 
    <groupId>org.springframework.boot</groupId> 
    <artifactId>spring-boot-starter-parent</artifactId> 
    <version>1.4.1.RELEASE</version> 
</parent> 
<dependencies> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-data-jpa</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-web</artifactId> 
     <exclusions> 
      <exclusion> 
       <groupId>org.springframework.boot</groupId> 
       <artifactId>spring-boot-starter-tomcat</artifactId> 
      </exclusion> 
      <exclusion> 
       <groupId>org.apache.tomcat</groupId> 
       <artifactId>tomcat-juli</artifactId> 
      </exclusion> 
      <exclusion> 
       <groupId>org.apache.tomcat</groupId> 
       <artifactId>tomcat-jdbc</artifactId> 
      </exclusion> 
     </exclusions> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-jetty</artifactId> 
    </dependency> 
    <!-- JPA Provider --> 
    <dependency> 
     <groupId>org.apache.openjpa</groupId> 
     <artifactId>openjpa-persistence</artifactId> 
     <version>2.4.1</version> 
    </dependency> 
    <dependency> 
     <groupId>org.apache.openjpa</groupId> 
     <artifactId>openjpa-maven-plugin</artifactId> 
     <version>2.4.1</version> 
    </dependency> 
    <dependency> 
     <groupId>org.apache.openjpa</groupId> 
     <artifactId>openjpa-all</artifactId> 
     <version>2.4.1</version> 
    </dependency> 
    <!-- MS SQL Server JDBC Driver --> 
    <!-- Manually install this plugin before adding in POM --> 
    <dependency> 
     <groupId>com.microsoft.sqlserver</groupId> 
     <artifactId>sqljdbc42</artifactId> 
     <version>4.2</version> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-test</artifactId> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>com.google.code.gson</groupId> 
     <artifactId>gson</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <scope>test</scope> 
    </dependency> 
</dependencies> 
<build> 
    <plugins> 
     <plugin> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-maven-plugin</artifactId> 
      <executions> 
       <execution> 
        <goals> 
         <goal>repackage</goal> 
        </goals> 
        <phase>none</phase> 
       </execution> 
      </executions> 
     </plugin> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-war-plugin</artifactId> 
      <configuration> 
       <packagingExcludes>WEB-INF/lib/tomcat-*.jar</packagingExcludes> 
      </configuration> 
     </plugin> 
     <plugin> 
      <groupId>org.apache.openjpa</groupId> 
      <artifactId>openjpa-maven-plugin</artifactId> 
      <version>2.4.1</version> 
      <configuration> 
       <includes>com.example.model/*.class</includes> 
       <excludes>**/entities/XML*.class</excludes> 
       <addDefaultConstructor>true</addDefaultConstructor> 
       <enforcePropertyRestrictions>true</enforcePropertyRestrictions> 
      </configuration> 
      <executions> 
       <execution> 
        <id>enhancer</id> 
        <phase>process-classes</phase> 
        <goals> 
         <goal>enhance</goal> 
        </goals> 
       </execution> 
      </executions> 
      <dependencies> 
       <dependency> 
        <groupId>org.apache.openjpa</groupId> 
        <artifactId>openjpa</artifactId> 
        <!-- set the version to be the same as the level in your runtime --> 
        <version>2.4.1</version> 
       </dependency> 
      </dependencies> 
     </plugin> 
    </plugins> 
    <finalName>configservice</finalName> 
</build> 

我在今年春天啓動的應用程序中使用OpenJPA與Spring的數據一起。我搜索了stackoverflow類似的錯誤,我發現他們的幾個決議,他們都沒有在我的情況下工作。我可以看到錯誤即將到來,因爲某處JPA 2.0正在使用。如何找出哪個庫正在使用JPA 2.0並刪除此錯誤?如果我通過使用嵌入式碼頭的maven運行相同的Spring引導應用程序,它可以很好地工作。

我已經看過這些鏈接 Hibernate NoSuchMethodError Spring boot NoSuchMethodError

+0

爲什麼你的OpenJPA爲您關聯持久性提供? spring-boot-starter-data-jpa默認使用Hibernate –

+0

OpenJPA提供更好的性能 – yogsma

回答

1

如果你想使用OpenJPA的,而不是休眠在春季啓動時,您必須排除的Hibernate的EntityManager

<dependency> 
    <groupId>org.springframework.boot</groupId> 
    <artifactId>spring-boot-starter-data-jpa</artifactId> 
    <exclusions> 
     <exclusion> 
      <groupId>org.hibernate</groupId> 
      <artifactId>hibernate-entitymanager</artifactId> 
     </exclusion> 
    </exclusions> 
</dependency> 

,然後配置的OpenJPA作爲持久性提供。

請找到這裏的EclipseLink一個例子: http://blog.marcnuri.com/spring-data-jpa-eclipselink-configuring-spring-boot-to-use-eclipselink-as-the-jpa-provider/

+0

如果我添加該排除,我會得到這個錯誤 - 「考慮在你的配置中定義一個名爲'entityManagerFactory'的bean。 – yogsma

+0

你讀過這篇文章了嗎? http://blog.marcnuri.com/spring-data-jpa-eclipselink-configuring-spring-boot-to-use-eclipselink-as-the-jpa-provider/ –