问题描述
import javax.ejb.EJB;
import stateless.Staff;
public class DisplayStaff扩展HttpServlet
{
private static final long serialVersionUID = 1L;
@EJB
private StaffBean Staff_bean;
....
}
没有这个注释和它的声明servlet作品被称为。使用注释我得到错误
根本原因
com.sun.enterprise.container.common .spi.util.InjectionException:为类创建托管对象时出错:class controllers.DisplayStaff
根本原因
com.sun.enterprise.container.common.spi.util。 InjectionException:异常尝试注入远程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导致
javax.naming.NamingException: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 resolve 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'。实际(可能是内部的)用于查找的远程JNDI名称是'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} [根异常是javax.naming.NameNotFoundException:stateless.StaffBean#stateless.StaffBean not found]]]
根本原因
javax.naming.NamingException:异常解析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'。实际(可能是内部的)用于查找的远程JNDI名称是'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} [根异常是javax.naming.NameNotFoundException:stateless.StaffBean#stateless.StaffBean not found]]
根本原因
javax.naming.NamingException:SerialContext中的'stateless.StaffBean#stateless.StaffBean'的查找失败[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} [根异常是javax.naming.NameNotF oundException:stateless.StaffBean#stateless.StaffBean not found]
根本原因
javax.naming.NameNotFoundException:stateless.StaffBean#stateless.StaffBean not found
注意在GlassFish Server开源版3.1.2日志中提供了异常的完整堆栈跟踪及其根本原因。
容器在。
您应该通常注入一个引用bean的远程或本地界面,而不是bean本身:
@EJB
private StaffBeanRemote Staff_bean;
但可以肯定的是,使用JNDI资源管理器(通常在应用程序服务器的管理控制台上)看看什么是确切的JNDI名称。还要确保bean本身已部署并运行正常(也可以在管理控制台上检查)
I have @EJB annotation such as this in my serlvet
import javax.ejb.EJB;
import stateless.Staff;
public class DisplayStaff extends HttpServlet
{
private static final long serialVersionUID = 1L;
@EJB
private StaffBean Staff_bean;
....
}
Without that annotation and its declaration the servlet works and is called . With the annotation I get the error
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.
The container cannot find your bean in the JNDI.
You should usually inject a reference to the remote or local interface of the bean, not the bean itself:
@EJB
private StaffBeanRemote Staff_bean;
But to be sure, use a JNDI explorer (usually on the admin console of your application server) to see what is the exact JNDI name. Also make sure that the bean itself is deployed and running ok (can be checked also on the admin console)
这篇关于@EJB注释崩溃了一个servlet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!