JBoss 6:将EJB注入servlet [英] JBoss 6: Injecting EJB into servlet

查看:87
本文介绍了JBoss 6:将EJB注入servlet的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

伙计们,

每次新版本的JBoss发布时,我不得不重新学习并浪费时间用这些东西,这让我很生气。

I am very annoyed by having to re-learn and waste time with this stuff every time a new version of JBoss rolls around.

我有一个在JNDI空间中发现并声明的无状态EJB:

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

我需要在servlet中使用此EJB,这是战争的一部分,而战争是包含EJB的EAR的一部分。我想用注射来做。

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;

我在JBoss日志中遇到异常。

I get an exception in JBoss logs.

当我使用更花哨的符号时,例如:

When I use a more flowery notation such as:

@EJB( mappedName = "UserManager" )
private UserManager userManager;

@EJB( mappedName = "DTalk/UserManager/local" ) // EAR is called DTalk
private UserManager userManager;

我在jboss中没有注入错误,但是注入的bean为空。

I get no injections errors in jboss but the injected bean is null.

这很疯狂,而且浪费大量时间,这使我感到疑问,为什么我不放弃Eclipse / jboss工具系列而转而使用NetBeans和GlsssFish。

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.

谢谢。

推荐答案

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

You are trying to inject (a proxy to) the bean instance itself, instead of its interface.

但是,根据您显示的部署日志记录,您仅通过JNDI的(本地)接口声明了该bean的边界。为了进行注入,您应该将要注入的变量声明为接口:

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;

或声明无接口视图应该为您的bean创建:

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;

这篇关于JBoss 6:将EJB注入servlet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆