注入的 EJB 有时为 Null
我通过 @EJB 注释使用无状态 EJB...大多数时候一切都正常工作,但似乎有时应该注入的内容会解析为 NULL,从而导致空指针异常。
什么可能导致这种间歇性问题?
I'm using a stateless EJB via the @EJB annotation... most of the time everything works as it should but it seems that from time to time what is supposed to be injected resolves to a NULL causing a null pointer exception.
What could cause this intermittent problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
JBoss 4.x 不会自动将 EJB 注入 Servlet/JSP/POJO。但它也不会抱怨注释,它在运行时根本不起作用,并且对象将保持为 Null。您必须使用 JNDI 查找。
来自 JBoss 文档:
示例:
请务必使用您的 EAR 名称作为您要查找的名称的第一个部分(上例中的
教程
)。参考文献:
4.2?
JBoss 4.x won't automatically inject EJB's into Servlets/JSPs/POJOs. But it won't complain about the annotations either, it simply won't work at runtime, and the objects will remain Null. You have to use JNDI lookup.
From the JBoss docs:
Example:
Be sure to use the name of your EAR as the first segment in the name you are looking up (
tutorial
in the example above).References:
4.2?
我知道已经晚了,但我们遇到了同样的问题。最重要的信息是,这种情况有时会发生,但我们无法找出原因。
他注意到的第二件事是“父”类中的字段存在问题,我们有一个类
在调试中
SomeAnotherRemote anotherEJB;
已正确初始化,但SessionStoreLocal sessionStoreEJB;
为空。我们找到了一些解决这个问题的方法,首先创建 EjbUtil 类:
并添加:
它看起来现在可以工作......也许它会帮助处理这个旧代码的人。
I know it's late, but we had the same problem. The most important information is that, this happens sometimes and we could not find out why.
Second thing that whe had noticed was that there was problem with fields that were in "parent" class f.e. we have a class
In debug
SomeAnotherRemote anotherEJB;
was correctly initialized butSessionStoreLocal sessionStoreEJB;
was null.We found some work around for this problem, first create EjbUtil class:
and add:
It looks like it works for now.... Maybe it will help someone dealing with this old code.