我正在尝试在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仅在编译时有效。要解决此问题,您必须在容器中配置类加载。
pom.xml
OpenShift JavaEE 6支持基于JBoss AS7。从AS7文档中的类加载:
jboss-deployment-structure.xml是JBoss特定的部署描述符,可用于以细粒度方式控制类加载。应将其放在META- INF(或用于Web部署的WEB-INF)的顶级部署中。它可以执行以下操作: Prevent automatic dependencies from being added Add additional dependencies ...
jboss-deployment-structure.xml是JBoss特定的部署描述符,可用于以细粒度方式控制类加载。应将其放在META- INF(或用于Web部署的WEB-INF)的顶级部署中。它可以执行以下操作:
Prevent automatic dependencies from being added Add additional dependencies ...
因此,您需要添加自定义jboss-deployment-structure.xml文件以将其排除hibernate- jpa-2.0-api在自动添加之外。
jboss-deployment-structure.xml
hibernate- jpa-2.0-api
根据OpenShift的文档:
<jboss-deployment-structure> <deployment> <exclusions> <module name="javax.persistence.api" /> </exclusions> </deployment> </jboss-deployment-structure>