JBoss 6:将 EJB 注入 servlet

发布于 2024-11-26 11:04:08 字数 1033 浏览 0 评论 0原文

各位,

每次新版本的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

很酷又爱笑 2024-12-03 11:04:08

您正在尝试注入(代理)bean 实例本身,而不是其接口。

然而,根据您显示的部署日志记录,您仅通过其(本地)接口声明了要在 JNDI 中绑定的 bean。为了实现注入,您应该将要注入的变量声明为接口:

@EJB
private UserManagerLocal userManager;

或者声明应该为您的 bean 创建一个 no-interface 视图:

@Stateless
@LocalBean
public class UserManager implements UserManagerLocal {
    ...
}

之后您可以像之前一样声明变量:

@EJB
private UserManager userManager;

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:

@EJB
private UserManagerLocal userManager;

OR declare that a no-interface view should be created for your bean:

@Stateless
@LocalBean
public class UserManager implements UserManagerLocal {
    ...
}

after which you can declare the variable as you did earlier:

@EJB
private UserManager userManager;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文