Jakarta ee TOMEE jpa eclipselink示例不起作用
TOMEE jpa eclipselink示例: 不适合我 EJBContainer.Createjbcontainer(p)在单元测试类(MovieTest)内部失败,出现以下异常:Jakarta ee TOMEE jpa eclipselink示例不起作用,jakarta-ee,ejb,eclipselink,apache-tomee,openejb,Jakarta Ee,Ejb,Eclipselink,Apache Tomee,Openejb,TOMEE jpa eclipselink示例: 不适合我 EJBContainer.Createjbcontainer(p)在单元测试类(MovieTest)内部失败,出现以下异常: ... INFO - Found EjbModule in classpath: c:\users\oren\projects\test\jpa-eclipselink\target\classes INFO - Beginning load: c:\users\oren\projects\test\jpa-e
...
INFO - Found EjbModule in classpath: c:\users\oren\projects\test\jpa-eclipselink\target\classes
INFO - Beginning load: c:\users\oren\projects\test\jpa-eclipselink\target\classes
INFO - Configuring enterprise application: C:\Users\Oren\Projects\Test\jpa-eclipselink
INFO - Closing DataSource: movieDatabase
java.lang.NoSuchMethodError: javax.ejb.Stateful.passivationCapable()Z
at org.apache.openejb.config.AnnotationDeployer$DiscoverAnnotatedBeans.deploy(AnnotationDeployer.java:1454)
at org.apache.openejb.config.AnnotationDeployer$DiscoverAnnotatedBeans.deploy(AnnotationDeployer.java:456)
at org.apache.openejb.config.AnnotationDeployer.deploy(AnnotationDeployer.java:371)
at org.apache.openejb.config.ConfigurationFactory$Chain.deploy(ConfigurationFactory.java:415)
at org.apache.openejb.config.ConfigurationFactory.configureApplication(ConfigurationFactory.java:1002)
at org.apache.openejb.OpenEjbContainer$Provider.createEJBContainer(OpenEjbContainer.java:321)
at javax.ejb.embeddable.EJBContainer.createEJBContainer(EJBContainer.java:56)
at org.superbiz.eclipselink.MoviesTest.test(MoviesTest.java:37)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:86)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:78)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:212)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:68)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
我试图用谷歌搜索java.lang.NoSuchMethodError:javax.ejb.Stateful.钝化能力,但没有找到任何线索
我对示例maven项目所做的唯一更改是:
<dependency>
<groupId>org.apache.openejb</groupId>
<artifactId>javaee-api</artifactId>
<version>6.0-6</version>
<scope>provided</scope>
</dependency>
org.apache.openejb
JavaEEAPI
6.0-6
假如
而不是:
<dependency>
<groupId>org.apache.openejb</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
org.apache.openejb
JavaEEAPI
7.0-快照
假如
因为第一个不会建造
谁能解释一下是什么问题,我已经花了几个小时没有成功
如果您查看一下javax.ejb.Stateful.钝化能力的jee7javadocs,您会发现 自:EJB3.2 由于JEE6使用EJB3.1,所以该方法仅在JEE7中引入
您使用的eclipselink版本似乎需要一个JEE7实现(这就是为什么他们将其放在依赖项列表中),并且无法与JEE6一起使用。如果您无法使用JavaEE 6.0.6进行构建, 我为您提供了我可以使用eclipselink、Tomee1.7.2和Mysql构建和运行的设置 事实上,我正试图做与您完全相同的事情(对我来说,花了几天时间),几分钟前,我终于用eclipselink运行了我的应用程序!!耶 下面是我的pom.xml的样子:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<!-- some of my project settings here -->
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<finalName>myprojectname</finalName>
<plugins>
<plugin>
<!-- org.apache.maven.plugins 3.3 for source v1.8 -->
</plugin>
</plugins>
</build>
<repositories>
<repository>
<releases>
<enabled>false</enabled>
</releases>
<snapshots/>
<id>apache-maven-snapshots</id>
<url>https://repository.apache.org/content/groups/snapshots</url>
</repository>
<repository>
<id>eclipselink-repo</id>
<name>EclipseLink Repository</name>
<url>http://www.eclipse.org/downloads/download.php?r=1&nf=1&file=/rt/eclipselink/maven.repo</url>
</repository>
</repositories>
<dependencies>
<!-- mojarra required for facesmessage on ViewExpiredException -->
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.faces</artifactId>
<version>2.2.12</version>
</dependency>
<!-- /mojarra -->
<!-- db connection required -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.38</version>
</dependency>
<!-- /db connection -->
<!-- JavaEE required -->
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
<!-- /JavaEE -->
<!-- OmniFaces required for JSF, @Eager, postback same request parameters, etc -->
<dependency>
<groupId>org.omnifaces</groupId>
<artifactId>omnifaces</artifactId>
<version>1.8.3</version>
</dependency>
<!-- /OmniFaces -->
<!-- some commons-io, commons-lang3, jackson, velocity, aws sdks not relevant i guess. -->
<!-- even thought this is in the tomee eclipselink sample, it is not required -->
<!--
<dependency>
<groupId>org.apache.openejb</groupId>
<artifactId>javaee-api</artifactId>
<version>6.0-6</version>
</dependency>
-->
<!-- openejb container -->
<dependency>
<groupId>org.apache.openejb</groupId>
<artifactId>openejb-core</artifactId>
<version>4.7.2</version>
<scope>provided</scope>
</dependency>
<!-- toplink dependencies -->
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
<version>2.4.2</version>
</dependency>
</dependencies>
<!-- <distributionManagement> section , i guess not relevant either. -->
</project>
和my resources.xml:
<Resource id="myprojectname-mysql-jdbc-jta-resource" type="javax.sql.DataSource">
jtaManaged = true
DataSourceCreator = tomcat
validationQuery = SELECT 1
initialSize = 2
removeAbandoned = true
removeAbandonedTimeout = 120
driverClassName = com.mysql.jdbc.Driver
url = jdbc:mysql://localhost/myprojectdb
UserName = usernamestring
password = passwordstring
testOnBorrow = true
</Resource>
jtaManaged=true
DataSourceCreator=tomcat
validationQuery=选择1
初始大小=2
RemoveBandoned=true
RemoveBandonedTimeout=120
driverClassName=com.mysql.jdbc.Driver
url=jdbc:mysql://localhost/myprojectdb
UserName=usernamestring
密码=密码字符串
testOnBorrow=true
注意在我的pom.xml中,我删除了test,因为我希望它们不仅用于测试,还用于产品
我将openejbcore
工件设置为4.7.2
和提供的,因为我在tomEE home(v1.7.2)/lib目录中找到了这个版本。如果TOME版本不同,openejb core的版本也不同
编辑:pom.xml中不需要openEJB javaee api,所以我把它注释掉了。
另外,EclipseLink 2.6.2不完全兼容,所以我将其更改为2.4.2。
请参阅:正如冲野博文善意建议的那样,使用以下依赖项:
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.openejb</groupId>
<artifactId>openejb-core</artifactId>
<version>4.7.2</version>
<scope>provided</scope>
</dependency>
爪哇
JavaEEAPI
7
假如
org.apache.openejb
openejb内核
4.7.2
假如
如果没有7.0-SNAPSHOT,该示例也可以运行谢谢,你解决了我的问题,我没有意识到6.0-6意味着JEE6。与EclipseLink或JPA无关。。。正如堆栈跟踪所示,这纯粹是EJB(openejb)。感谢您为提供解决方案所做的努力
<Resource id="myprojectname-mysql-jdbc-jta-resource" type="javax.sql.DataSource">
jtaManaged = true
DataSourceCreator = tomcat
validationQuery = SELECT 1
initialSize = 2
removeAbandoned = true
removeAbandonedTimeout = 120
driverClassName = com.mysql.jdbc.Driver
url = jdbc:mysql://localhost/myprojectdb
UserName = usernamestring
password = passwordstring
testOnBorrow = true
</Resource>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.openejb</groupId>
<artifactId>openejb-core</artifactId>
<version>4.7.2</version>
<scope>provided</scope>
</dependency>