JBoss 6:将 EJB 注入 servlet
各位,
每次新版本的 JBoss 推出时,我都必须重新学习并浪费时间在这些东西上,这让我非常恼火。
我有一个在 JNDI 空间中发现并声明的无状态 EJB:
10:01:53,044 INFO [org.jboss.ejb3.proxy.impl.jndiregistrar.JndiSessionRegistrarBase] Binding the following Entries in Global JNDI:
DTalk/UserManager/local - EJB3.x Default Local Business Interface
DTalk/UserManager/local-com.doctalk.ejb.UserManagerLocal - EJB3.x Local Business Interface
我需要在 servlet 中使用此 EJB,该 servlet 是 war 的一部分,而 war 是包含该 EJB 的 EAR 的一部分。我想使用注射来做到这一点。
当我使用最直观的符号时:
@EJB
private UserManager userManager;
我在 JBoss 日志中收到异常。
当我使用更华丽的符号时,例如:
@EJB( mappedName = "UserManager" )
private UserManager userManager;
或者
@EJB( mappedName = "DTalk/UserManager/local" ) // EAR is called DTalk
private UserManager userManager;
我在 jboss 中没有收到注入错误,但注入的 bean 为空。
这令人抓狂,而且是对时间的巨大浪费,让我质疑为什么我不放弃 Eclipse/jboss 工具专营权而转而使用 NetBeans 和 GlsssFish。
任何见解表示赞赏。
谢谢。
Folks,
I am very annoyed by having to re-learn and waste time with this stuff every time a new version of JBoss rolls around.
I have a stateless EJB that is discovered and declared in the JNDI space:
10:01:53,044 INFO [org.jboss.ejb3.proxy.impl.jndiregistrar.JndiSessionRegistrarBase] Binding the following Entries in Global JNDI:
DTalk/UserManager/local - EJB3.x Default Local Business Interface
DTalk/UserManager/local-com.doctalk.ejb.UserManagerLocal - EJB3.x Local Business Interface
I need to use this EJB in a servlet which is part of a war which is part of the EAR that contains the EJB. I'd like to do it using injection.
When I use the most intuitive notation:
@EJB
private UserManager userManager;
I get an exception in JBoss logs.
When I use a more flowery notation such as:
@EJB( mappedName = "UserManager" )
private UserManager userManager;
Or
@EJB( mappedName = "DTalk/UserManager/local" ) // EAR is called DTalk
private UserManager userManager;
I get no injections errors in jboss but the injected bean is null.
This is maddening and a huge waste of time and makes me question why I don't dump the Eclipse/jboss tools franchise in favor of NetBeans and GlsssFish.
Any insights appreciated.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在尝试注入(代理)bean 实例本身,而不是其接口。
然而,根据您显示的部署日志记录,您仅通过其(本地)接口声明了要在 JNDI 中绑定的 bean。为了实现注入,您应该将要注入的变量声明为接口:
或者声明应该为您的 bean 创建一个
no-interface
视图:之后您可以像之前一样声明变量:
You are trying to inject (a proxy to) the bean instance itself, instead of its interface.
Yet, according to the deployment logging you've shown, you have only declared the bean to be bounded in JNDI via its (local) interface. In order to make the injection happen, you should either declare the variable in which you're injecting as the interface:
OR declare that a
no-interface
view should be created for your bean:after which you can declare the variable as you did earlier: