使用 @Inject 将无状态 EJB 注入 CDI Weld ManagedBean(jboss 6 AS 上的 JSF 1.2 EJB 应用程序)
目前,我正在尝试将无状态 EJB 注入 Jboss 6 AS Final 上的 CDI 托管控制器中。控制器在可从 JSF 页面访问的上下文中进行管理。如果我用 @EJB
注入无状态 bean,它就可以工作。如果我使用 @Inject
注入无状态 EJB,则会出现以下异常:
我的控制器:
@Named("TestController")
public class TestController {
@Inject
private TestManagerLocal myTestManager;
...
}
}
我的无状态 bean:
@SuppressWarnings("unchecked")
@Stateless
public class TestManagerBean implements TestManagerLocal {
@PersistenceContext
private EntityManager em;
...
}
Bean 的接口用 @Local 进行注释。
如果我尝试调用 myTestManager 我会收到以下异常:
WELD-000079 在 JNDI 中找不到 EJB:类 de.crud.org$jboss$weld$bean-jboss$classloader:id="vfs:$$$usr$local$jboss$server$default$deploy$test$ear"-SessionBean-TestManagerBean_$$_WeldProxy
非常感谢。
Currently I am trying to inject a stateless EJB into a CDI managed controller on Jboss 6 AS Final. The controller is managed in the context an accessible from the JSF pages. If I inject the stateless bean with @EJB
it is working. If I inject the stateless EJB with @Inject
I get the following Exception:
My controller:
@Named("TestController")
public class TestController {
@Inject
private TestManagerLocal myTestManager;
...
}
}
My stateless bean:
@SuppressWarnings("unchecked")
@Stateless
public class TestManagerBean implements TestManagerLocal {
@PersistenceContext
private EntityManager em;
...
}
The Interface of the Bean is annotated with @Local.
If I try to call myTestManager I get the following exception:
WELD-000079 Could not find the EJB in JNDI: class
de.crud.org$jboss$weld$bean-jboss$classloader:id="vfs:$$$usr$local$jboss$server$default$deploy$test$ear"-SessionBean-TestManagerBean_$$_WeldProxy
THX a lot.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
对于那些没有能力改变对战争的态度的人,我找到了以下解决方法:
@Inject 以及那些生产者方法的限定符:
代码:
现在,来自 EAR 中任何位置的 EJB 都可以注入:
EJBBean 是一个简单的标准限定符注释。为了完整起见,这里是:
For those not having the luxury to change an ear to a war, I've found the following workaround:
@Inject
with the qualifier for those producer methods:Code:
Now EJBs from anywhere in the EAR can be injected with:
EJBBean is a simple standard qualifier annotation. For completeness, here it is:
问题是,我构建并部署了我的应用程序作为耳朵。当我将应用程序部署为战争(包括所有 EJB)时,Weld 正在工作。
The problem was, that I built and deployed my application as an ear. Weld is working when I deploy my application as an war including all EJBs.
目前,由于 EAR 部署中的 WAR 不共享相同的类加载器,因此出现了各种问题。请参阅 https://issues.jboss.org/browse/JBAS-8683 了解正在进行的JBoss-AS JIRA 中的讨论(并投票支持:-) )
更新 我在 如何禁用单独的类加载器,选项 1 对我有用,但要非常小心。类加载器的分离并不是无缘无故地被引入的,所以显然前面的道路上出现了新的问题......
Currently there are various problems arising from the fact that WARs in EAR-Deployments don't share the same classloader. See https://issues.jboss.org/browse/JBAS-8683 for the ongoing discussion in the JBoss-AS JIRA (and vote it up :-) )
UPDATE I found this information on how to disable separate classloaders, option 1 worked for me, but be extremely careful with this. The separation of classloaders hasn't been introduced for no reason, so apparently there are new problems on the road ahead...