我有一个 EAR 文件,它定义了 EJB-JAR、WAR 和一堆其他 JAR 文件。我有一个ejb-jar-1.jar
定义 EJB、服务和实体。它还persistence.xml
在META-INF
文件夹中定义。在app-war.war
我定义了components.xml
哪些声明persistence:entity-manager-factor
和persistence:mananged-persistence-context
元素。现在,在我的一项服务中,ejb-jar-1.jar
使用@PersistenceContext
注解注入一个EntityManager
. 但是当代码运行时EntityManager
,该服务总是NULL
. 我不确定发生了什么。只是EntityManager
它无法注入所有其他注入正常工作。项目结构如下。
有关如何解决此问题的任何建议?指针也会有所帮助。我正在升级项目以在 JBOSS 7.1.1.Final 上运行。
部署信息
* JBOSS 7.1.1.FINAL
* Uses seam framework: jboss-seam-2.2.1.CR2.jar
* Uses Hibernate 3.4.0.GA
主耳
|__META-INF
| |____jboss-deployment-structure.xml
| |____application.xml
| |____jboss-app.xml
| |____MANIFEST.MF
|__lib
| |____somejar.jar
| |____somejar.jar
|__ejb-jar-1.jar
| |____META-INF
| |____persistence.xml
|__ejb-jar-2.jar
|__jboss-seam-2.2.1.CR2.jar
|__commons-lang-2.4.jar
|__commons-codec-1.1.jar
|__jasypt-1.6.jar
|__app-war.war
|____components.xml
jboss-部署-结构.xml
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.0">
<ear-subdeployments-isolated>false</ear-subdeployments-isolated>
<deployment>
<exclusions>
<module name="javax.faces.api" slot="1.2"/>
<module name="com.sun.jsf-impl" slot="1.2"/>
<module name="org.hibernate" slot="main"/>
<module name="org.hibernate.validator" slot="main"/>
<module name="org.apache.commons.lang"/>
<module name="org.apache.commons.collections"/>
<module name="org.apache.commons.codec"/>
<module name="org.picketlink" slot="main"/>
<module name="org.picketbox" slot="main"/>
<module name="org.javassist" slot="main"/>
<module name="org.dom4j" slot="main"/>
</exclusions>
<dependencies>
<module name="javax.faces.api" slot="1.2" export="true"/>
<module name="com.sun.jsf-impl" slot="1.2" export="true"/>
<module name="org.javassist" slot="1" export="true"/>
<module name="org.apache.commons.logging" export="true"/>
</dependencies>
</deployment>
<sub-deployment name="app-war.war">
<exclusions>
<module name="javax.faces.api" slot="main"/>
<module name="com.sun.jsf-impl" slot="main"/>
</exclusions>
<dependencies>
<module name="javax.faces.api" slot="1.2"/>
<module name="com.sun.jsf-impl" slot="1.2"/>
<module name="deployment.main-ear.ear.ejb-jar-1.jar" />
<module name="deployment.main-ear.ear.ejb-jar-2.jar" />
<module name="deployment.main-ear.ear.jboss-seam-2.2.1.CR2.jar"/>
</dependencies>
</sub-deployment>
<module name="deployment.main-ear.ear.jasypt-1.6.jar" />
<module name="deployment.main-ear.ear.commons-codec-1.1.jar" />
<module name="deployment.main-ear.ear.commons-lang-2.4.jar" />
</jboss-deployment-structure>
应用程序.xml
<?xml version="1.0" encoding="UTF-8"?>
<application xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/javaee/application_6.xsd"
version="6">
<description>myapp</description>
<display-name>myapp</display-name>
<initialize-in-order>true</initialize-in-order>
<library-directory>lib</library-directory>
<module>
<ejb>ejb-jar-1.jar</ejb>
</module>
<module>
<ejb>ejb-jar-2.jar</ejb>
</module>
<module>
<ejb>jboss-seam-2.2.1.CR2.jar</ejb>
</module>
<module>
<web>
<web-uri>app-war.war</web-uri>
<context-root>/app</context-root>
</web>
</module>
</application>
组件.xml
<?xml version="1.0" encoding="UTF-8"?>
<components ...>
<core:init debug="@debug@" jndi-pattern="@jndiPattern@" security-enabled="@seamSecurity@" precedence="30" />
<persistence:entity-manager-factory name="entityManagerFactory" persistence-unit-name="coreUnit" precedence="30"/>
<persistence:managed-persistence-context name="entityManager" auto-create="true" entity-manager-factory="#{entityManagerFactory}" precedence="30"/>
<security:persistent-permission-resolver permission-store="#{cacheEnabledJpaPermissionStore}" />
<transaction:ejb-transaction precedence="30"/>
...
</components>