gpt4 book ai didi

java - NoSuchMethodError : javax. persistence.JoinColumn.foreignKey()

转载 作者:行者123 更新时间:2023-11-30 08:59:50 25 4
gpt4 key购买 nike

我正在尝试在 OpenShift(JBoss 企业应用程序平台 6)上部署我的应用程序,但出现标题中提到的 NoSuchMethodError。所以我用谷歌搜索了整个事情,发现了一些文章或线程提到这个方法自 JPA-API 2.1 以来可用。我发现 Openshift 所必需的依赖项包含 JPA-API 2.0。我试图排除这种依赖性,但它不起作用。有任何想法吗?请在下面找到 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>christmasmarkets</groupId>
<artifactId>christmasmarkets</artifactId>
<packaging>war</packaging>
<version>1.0</version>
<name>christmasmarkets</name>
<repositories>
<repository>
<id>eap</id>
<url>http://maven.repository.redhat.com/techpreview/all</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>springsource-repo</id>
<name>SpringSource Repository</name>
<url>http://repo.springsource.org/release</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>eap</id>
<url>http://maven.repository.redhat.com/techpreview/all</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
<spring.version>4.1.2.RELEASE</spring.version>
<hibernate.version>4.3.7.Final</hibernate.version>
<hibernate-annotations.version>3.5.6-Final</hibernate-annotations.version>
<hibernate-commons-annotations.version>3.2.0.Final</hibernate-commons-annotations.version>
<jackson.version>2.2.3</jackson.version>
<postgre.version>9.3-1102-jdbc41</postgre.version>
</properties>
<dependencies>
<dependency>
<groupId>org.jboss.spec</groupId>
<artifactId>jboss-javaee-6.0</artifactId>
<version>3.0.2.Final-redhat-4</version>
<type>pom</type>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.0-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>${hibernate.version}</version>
</dependency>

<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>${postgre.version}</version>
</dependency>

</dependencies>
<profiles>
<profile>
<!-- When built in OpenShift the 'openshift' profile will be used when
invoking mvn. -->
<!-- Use this profile for any OpenShift specific customization your app
will need. -->
<!-- By default that is to put the resulting archive into the 'deployments'
folder. -->
<!-- http://maven.apache.org/guides/mini/guide-building-for-different-environments.html -->
<id>openshift</id>
<build>
<finalName>christmasmarkets</finalName>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<outputDirectory>deployments</outputDirectory>
<warName>ROOT</warName>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>

最佳答案

这里的问题是容器在运行时提供了 JPA 2.0。在 pom.xml 中排除提供的依赖项仅在编译时有效。要解决这个问题,必须在容器中配置类加载。

OpenShift JavaEE 6 支持基于 JBoss AS 7。来自 Class Loading in AS7文档:

jboss-deployment-structure.xml is a JBoss specific deployment descriptor that can be used to control class loading in a fine grained manner. It should be placed in the top level deployment, in META-INF (or WEB-INF for web deployments). It can do the following:

   Prevent automatic dependencies from being added
Add additional dependencies
...

因此,您需要添加自定义 jboss-deployment-structure.xml 文件以排除自动添加 hibernate-jpa-2.0-api

基于 OpenShift's documentation :

<jboss-deployment-structure>
<deployment>
<exclusions>
<module name="javax.persistence.api" />
</exclusions>
</deployment>
</jboss-deployment-structure>

关于java - NoSuchMethodError : javax. persistence.JoinColumn.foreignKey(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27077054/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com