我有一个调用 ejb 有状态会话 bean 代码的 servlet 代码,如下所示,
public class UsesBeansSF extends HttpServlet {
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
// do something
}
finally {}
}
private SessionBeanSFRemote lookupSessionBeanSFRemote() {
try {
Context c = new InitialContext();
return (SessionBeanSFRemote) c.lookup("java:global/MyEJBSF/SessionBeanSF!ejbSF.SessionBeanSFRemote");
} catch (NamingException ne) {
Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", ne);
throw new RuntimeException(ne);
}
}
}
此代码在没有 * 标记之间的情况下运行良好。但是,当我添加SessionBeanSFRemote sessionBeanSF = lookupSessionBeanSFRemote()这一行(意味着调用有状态会话 Bean)时,代码给出了错误。实际上,我必须调用无状态会话 bean 才能执行某些工作。谁能帮助我为什么会这样?提前致谢。
错误信息如下:
类型异常报告消息
descriptionThe server encountered an internal error () that prevented it from fulfilling this request.
例外
javax.servlet.ServletException: PWC1392: Error instantiating servlet class websSF.comsSF.UsesBeansSF
根本原因
com.sun.enterprise.container.common.spi.util.InjectionException:
Error creating managed object for class websSF.comsSF.UsesBeansSF
根本原因
java.lang.reflect.InvocationTargetException
根本原因
java.lang.RuntimeException: javax.naming.NamingException:
Lookup failed for 'java:global/MyEJBSF/SessionBeanSF!ejbSF.SessionBeanSFRemote' in SerialContext
[Root exception is javax.naming.NamingException:
ejb ref resolution error for remote business interfaceejbSF.SessionBeanSFRemote [Root exception is java.lang.NullPointerException]]
根本原因
javax.naming.NamingException:
Lookup failed for 'java:global/MyEJBSF/SessionBeanSF!ejbSF.SessionBeanSFRemote' in SerialContext
[Root exception is javax.naming.NamingException:
ejb ref resolution error for remote business interfaceejbSF.SessionBeanSFRemote
[Root exception is java.lang.NullPointerException]]
根本原因
javax.naming.NamingException: ejb ref resolution error for remote business
interfaceejbSF.SessionBeanSFRemote [Root exception is java.lang.NullPointerException]
根本原因
java.lang.NullPointerException
note The full stack traces of the exception and its root causes are available in the GlassFish Server Open Source Edition 3.0.1 logs.
服务器:GlassFish Server 开源版 3.0.1