【发布时间】:2015-12-27 00:48:30
【问题描述】:
使用环境
Netbeans 8.0+
玻璃鱼 4+
jdk 1.8
请注意,如果您不使用界面视图,则此示例效果很好。如果我们使用本地或远程界面,则效果不佳
远程界面
package packt;
import javax.ejb.Remote;
@Remote
public interface SphereBeanRemote {
public double computeVolume(double radius);
}
上述接口的实现
package packt;
import javax.ejb.Stateless;
@Stateless
public class SphereBean implements SphereBeanRemote {
@Override
public double computeVolume(double radius) {
return (4.0/3.0)*Math.PI*(radius*radius*radius);
}
}
访问它的客户端(servlet)
import java.io.*;
import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
import packt.SphereBean;
@WebServlet(urlPatterns = {"/SphereServlet"})
public class SphereServlet extends HttpServlet {
@EJB
SphereBean sphere;
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
try (PrintWriter out = response.getWriter()) {
out.println("<!DOCTYPE html>");
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet SphereServlet</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Servlet SphereServlet at " + request.getContextPath() + "</h1>");
out.println("<h1>" + sphere.computeVolume(18) + "</h1>");
out.println("</body>");
out.println("</html>");
}
}
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
@Override
public String getServletInfo() {
return "Short description";
}
}
错误 HTTP 状态 500 - 内部服务器错误
输入异常报告
消息内部服务器错误
描述服务器遇到了一个内部错误,导致它无法完成这个请求。
异常
javax.servlet.ServletException: 实例化 servlet 类 SphereServlet 时出错
根本原因
com.sun.enterprise.container.common.spi.util.InjectionException:为类创建托管对象时出错:类 SphereServlet
根本原因
com.sun.enterprise.container.common.spi.util.InjectionException: 尝试注入远程 ejb-ref name=SphereServlet/sphere,Remote 3.x interface =packt.SphereBean,ejb-link=null,lookup 的异常=,mappedName=,jndi-name=packt.SphereBean,refType=Session 进入类 SphereServlet:在 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。命名}
根本原因
javax.naming.NamingException:在 SerialContext [myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java 中查找“java:comp/env/SphereServlet/sphere”失败.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [根异常是 javax.naming.NamingException :为“远程 ejb-ref name=SphereServlet/sphere,Remote 3.x interface =packt.SphereBean,ejb-link=null,lookup=,mappedName=,jndi-name=packt.SphereBean,refType=Session”解析 Ejb 的异常.用于查找的实际(可能是内部)远程 JNDI 名称是“packt.SphereBean#packt.SphereBean”[根异常是 javax.naming.NamingException:在 SerialContext[myEnv={java] 中查找“packt.SphereBean#packt.SphereBean”失败.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: packt.SphereBean#packt.SphereBean not found]]]
根本原因
javax.naming.NamingException: 为 'Remote ejb-ref name=SphereServlet/sphere,Remote 3.x interface =packt.SphereBean,ejb-link=null,lookup=,mappedName=,jndi-name= 解析 Ejb 异常packt.SphereBean,refType=Session' 。用于查找的实际(可能是内部)远程 JNDI 名称是“packt.SphereBean#packt.SphereBean”[根异常是 javax.naming.NamingException:在 SerialContext[myEnv={java] 中查找“packt.SphereBean#packt.SphereBean”失败.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: packt.SphereBean#packt.SphereBean not found]]
根本原因
javax.naming.NamingException:在 SerialContext [myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming 中查找“packt.SphereBean#packt.SphereBean”失败.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [根异常是 javax.naming.NameNotFoundException: packt .SphereBean#packt.SphereBean 未找到]
根本原因
javax.naming.NameNotFoundException: 未找到 packt.SphereBean#packt.SphereBean
note GlassFish Server Open Source Edition 4.1 日志中提供了异常的完整堆栈跟踪及其根本原因。 GlassFish Server 开源版 4.1
【问题讨论】:
标签: jakarta-ee glassfish ejb-3.0 ejb-3.1