Dependency injection Geronimo 3.0中EJB模块的上下文注入
我试图使用EJB3注释注入PersistenceContext,但geronimo不注入依赖项。它是一个由EJB和WEB模块组成的EAR项目 EJB模块配置Dependency injection Geronimo 3.0中EJB模块的上下文注入,dependency-injection,ejb-3.0,openjpa,entitymanager,geronimo,Dependency Injection,Ejb 3.0,Openjpa,Entitymanager,Geronimo,我试图使用EJB3注释注入PersistenceContext,但geronimo不注入依赖项。它是一个由EJB和WEB模块组成的EAR项目 EJB模块配置 <?xml version="1.0" encoding="UTF-8" standalone="no"?> <ejb:openejb-jar xmlns:app="http://geronimo.apache.org/xml/ns/j2ee/application-2.0" xmlns:bp="http:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<ejb:openejb-jar
xmlns:app="http://geronimo.apache.org/xml/ns/j2ee/application-2.0"
xmlns:bp="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:client="http://geronimo.apache.org/xml/ns/j2ee/application-client-2.0"
xmlns:conn="http://geronimo.apache.org/xml/ns/j2ee/connector-1.2"
xmlns:dep="http://geronimo.apache.org/xml/ns/deployment-1.2" xmlns:ejb="http://openejb.apache.org/xml/ns/openejb-jar-2.2"
xmlns:jaspi="http://geronimo.apache.org/xml/ns/geronimo-jaspi"
xmlns:log="http://geronimo.apache.org/xml/ns/loginconfig-2.0"
xmlns:name="http://geronimo.apache.org/xml/ns/naming-1.2" xmlns:pers="http://java.sun.com/xml/ns/persistence"
xmlns:pkgen="http://openejb.apache.org/xml/ns/pkgen-2.1" xmlns:sec="http://geronimo.apache.org/xml/ns/security-2.0"
xmlns:web="http://geronimo.apache.org/xml/ns/j2ee/web-2.0.1">
<dep:environment>
<dep:moduleId>
<dep:groupId>wedge</dep:groupId>
<dep:artifactId>wedge-ejb</dep:artifactId>
<dep:version>1.0</dep:version>
<dep:type>car</dep:type>
</dep:moduleId>
<dep:dependencies>
<dep:dependency>
<dep:groupId>console.dbpool</dep:groupId>
<dep:artifactId>jdbc_wedgeDS</dep:artifactId>
<dep:version>1.0</dep:version>
<dep:type>car</dep:type>
</dep:dependency>
</dep:dependencies>
</dep:environment>
我已验证事务开始/结束正常,但未注入entityManager
一些想法
提前谢谢
Saul您不需要指定全局jndi名称。像这样将其注入servlet:
@EJB
private PruebaBL pruebaBL;
我正在阅读日志并进行调试,我认为问题在于如何将EJB注入WebServlet。我是否需要在@EJB注释中指定jndi全局名称?i、 e.
@EJB(name=java:comp/env/global/wedge/wedge-EJB/PruebaBLImpl!wedge.EJB.PruebaBL)
。如果此引用失败,将使用“new”创建Pojo,并且注入失败。对吗?感谢您,我以这种方式成功地部署了EJB,即使没有@Local。问题仍然存在,我无法使用EJB和Servlet中注入的persistenceContext。本周末,我将使用postgresql部署相同的配置,部署不同的XA数据源。非常感谢。
@Local(PruebaBL.class)
@Stateless
public class PruebaBLImpl {
@PersistenceContext()
private EntityManager em;
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void metodoPrueba(HttpServletResponse response) throws IOException, NamingException {
if (em == null) {
response.getOutputStream().println("entity manager is null");
}
@EJB
private PruebaBL pruebaBL;