【发布时间】:2019-10-23 20:06:25
【问题描述】:
我是 java EE 的新手。最近我在做一个使用bean stateless的项目,但是我得到了以下错误
豆子:
@Stateless(mappedName = "FlightServiceBean")
public class FlightServiceBean {
public FlightServiceBean() {
}
// data
}
小服务程序:
private FlightServiceBean fs = null;
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
PrintWriter out = response.getWriter();
out.println("The flights details servlet has been called ...");
try
{
Context context = new InitialContext();
fs = (FlightServiceBean) context.lookup("java:global/ejb1/FlightServiceBean!com.airline.service.FlightServiceBean");
// here where I got the exception
}
catch (NamingException e)
{
System.out.println("Naming Exception has occurred when trying to lookup the flightService EJB");
e.printStackTrace();
}
javax.naming.NamingException:在 SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming 中查找“java:global/ejb1/FlightServiceBean!com.airline.service.FlightServiceBean”失败.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: ejb1]
注意:我使用的是 glassfish 5.0 和 jdk 1.8.0
【问题讨论】:
-
该代码属于哪个类? FlightServiceBean 是在哪里声明的?
-
在 com.airline.service
-
IntelliJ can't find your FlightServiceBean 是错误消息所说的。我认为您的问题可能类似于stackoverflow.com/questions/20801241/…
-
我不认为这是错误,因为即使我插入了错误的名称,它也会给出同样的错误
-
正确的 JNDI 名称取决于应用程序的部署方式。请描述您的部署结构。
标签: java jakarta-ee glassfish ejb javabeans