我有一个注入的无状态 EJB
@PersistenceUnit
private EntityManagerFactory factory
我的persistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="ejbPU-ro" transaction-type="RESOURCE_LOCAL">
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
<non-jta-data-source>mySQLDataSource</non-jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="openjpa.jdbc.DBDictionary" value="mysql"/>
<property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(foreignKeys=true"/>
<property name="openjpa.jdbc.SchemaFactory" value="native(foreignKeys=true)"/>
<property name="openjpa.Log" value="DefaultLevel=INFO,SQL=INFO"/>
</properties>
</persistence-unit>
</persistence>
当我使用单元测试时:
Properties p = new Properties();
p.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.core.LocalInitialContextFactory");
p.setProperty(Context.PROVIDER_URL, "http://127.0.0.1:4204/openejb/ejb");
InitialContext initialContext = new InitialContext(p);
还定义了openejb.home
VM arg 和单元测试完美运行。
部署到 TomEE 时,我在my.war/WEB-INF/lib/my.jar/META-INF
.
在conf/tomee.xml
我有:
<JndiProvider id="prov" type="javax.naming.InitialContext">
java.naming.factory.initial = org.apache.openejb.core.LocalInitialContextFactory
java.naming.provider.url = http://127.0.0.1:4204/openejb/ejb
</JndiProvider>
和:
<Resource id="mySQLDataSource" type="DataSource">
JdbcDriver com.mysql.jdbc.Driver
JdbcUrl jdbc:mysql://127.0.0.1:3306/mydb
UserName root
Password
JtaManaged false
DefaultAutoCommit false
</Resource>
日志看起来不错,但是当我运行代码时,注入的工厂为空。
有任何想法吗?