@EJB注释崩溃了一个servlet

时间:2012-07-14 08:12:51

标签: java servlets ejb

我的servlet

中有@EJB注释
import javax.ejb.EJB;
import stateless.Staff;
public class DisplayStaff extends HttpServlet 
{
    private static final long serialVersionUID = 1L;

        @EJB
        private StaffBean Staff_bean;
        ....
}

如果没有该注释及其声明,则servlet可以正常工作并被调用。使用注释我得到错误

root cause

com.sun.enterprise.container.common.spi.util.InjectionException: Error creating managed object for class: class controllers.DisplayStaff

root cause

com.sun.enterprise.container.common.spi.util.InjectionException: Exception attempting to inject Remote ejb-ref name=controllers.DisplayStaff/Stud_bean,Remote 3.x interface =stateless.StaffBean,ejb-link=null,lookup=,mappedName=,jndi-name=stateless.StaffBean,refType=Session into class controllers.DisplayStaff: Lookup failed for 'java:comp/env/controllers.DisplayStaff/Stud_bean' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming}

root cause

javax.naming.NamingException: Lookup failed for 'java:comp/env/controllers.DisplayStaff/Stud_bean' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.NamingException: Exception resolving Ejb for 'Remote ejb-ref name=controllers.DisplayStaff/Stud_bean,Remote 3.x interface =stateless.StaffBean,ejb-link=null,lookup=,mappedName=,jndi-name=stateless.StaffBean,refType=Session' .  Actual (possibly internal) Remote JNDI name used for lookup is 'stateless.StaffBean#stateless.StaffBean' [Root exception is javax.naming.NamingException: Lookup failed for 'stateless.StaffBean#stateless.StaffBean' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.NameNotFoundException: stateless.StaffBean#stateless.StaffBean not found]]]

root cause

javax.naming.NamingException: Exception resolving Ejb for 'Remote ejb-ref name=controllers.DisplayStaff/Stud_bean,Remote 3.x interface =stateless.StaffBean,ejb-link=null,lookup=,mappedName=,jndi-name=stateless.StaffBean,refType=Session' .  Actual (possibly internal) Remote JNDI name used for lookup is 'stateless.StaffBean#stateless.StaffBean' [Root exception is javax.naming.NamingException: Lookup failed for 'stateless.StaffBean#stateless.StaffBean' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.NameNotFoundException: stateless.StaffBean#stateless.StaffBean not found]]

root cause

javax.naming.NamingException: Lookup failed for 'stateless.StaffBean#stateless.StaffBean' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.NameNotFoundException: stateless.StaffBean#stateless.StaffBean not found]

root cause

javax.naming.NameNotFoundException: stateless.StaffBean#stateless.StaffBean not found

note The full stack traces of the exception and its root causes are available in the GlassFish Server Open Source Edition 3.1.2 logs.

2 个答案:

答案 0 :(得分:1)

容器无法在JNDI中找到您的bean。

通常应该引用bean的远程或本地接口的引用,而不是bean本身:

@EJB
private StaffBeanRemote Staff_bean;

但是可以肯定的是,使用JNDI资源管理器(通常在应用程序服务器的管理控制台上)来查看确切的JNDI名称。还要确保bean本身已部署并正常运行(也可在管理控制台上查看)

答案 1 :(得分:-1)

将引用的bean声明为static。

@EJB
private static StaffBean Staff_bean;

希望这有效。 谢谢