我有一个EAR文件,其结构如下:
jar.jar包含两个接口
TestServlet注入Test1,只有在war.war到ejb.jar中有一个清单类路径条目时才解析为Test1Impl。Test1Impl注入解析为Test2Impl的Test2,只有在ejb.jar到war.war中有一个清单类路径条目的情况下。
贴士条目与焊接文件的部署的类加载器结构相匹配,解释了为什么我需要清单条目。这种交叉BDA注射是如何正常工作的?添加类路径清单条目似乎有点愚蠢,因为实际上我不希望实现是可见的。我只希望其他子部署中的bean是可见的。有什么办法吗?
在这里实现
public class Test1Impl implements Test1 {
@Inject
private Test2 test2;
public void hello() {
System.out.println(test2.getString());
}
}
public class Test2Impl implements Test2 {
public String getString() {
return "Hello";
}
}
@WebServlet(urlPatterns = "/test")
public class TestServlet implements Servlet {
@Inject
private Test1 test;
public void init(ServletConfig config) throws ServletException {
}
public ServletConfig getServletConfig() {
return null;
}
public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
test.hello();
}
public String getServletInfo() {
return null;
}
public void destroy() {
}
}在这里,application.xml
<?xml version="1.0" encoding="UTF-8"?>
<application xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/application_7.xsd"
version="7">
<description>The EAR</description>
<display-name>ear</display-name>
<module>
<ejb>ejb.jar</ejb>
</module>
<module>
<web>
<web-uri>war.war</web-uri>
<context-root>/</context-root>
</web>
</module>
<library-directory>lib</library-directory>
</application>发布于 2014-08-25 18:47:26
正如CDI参考在一节中所描述的那样,使用来自部署外部的CDI,需要一个具有适当依赖关系的jboss-deployment-structure.xml。虽然这样做解决了我的问题,但我认为CDI规范应该为企业应用程序定义一种可移植的方法。
https://stackoverflow.com/questions/25474530
复制相似问题