gpt4 book ai didi

javax.naming.NamingException : Lookup failed - Intellij Idea

转载 作者:行者123 更新时间:2023-12-02 04:42:21 25 4
gpt4 key购买 nike

我是 java EE 的新手。最近我正在开发一个使用 bean stateless 的项目,但出现以下错误

bean :

@Stateless(mappedName = "FlightServiceBean")
public class FlightServiceBean {

public FlightServiceBean() {
}

// data

}

Servlet:

  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: Lookup failed for 'java:global/ejb1/FlightServiceBean!com.airline.service.FlightServiceBean' 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: ejb1]

This is my project structure

注意:我使用的是 glassfish 5.0 和 jdk 1.8.0

最佳答案

您的 EJB 查找不正确。尝试将上面的行更改为

 fs = (FlightServiceBean) ic.lookup("java:comp/env/ejb/FlightServiceBean");

有关 EJB 查找的更多信息,请参阅此 link .

关于javax.naming.NamingException : Lookup failed - Intellij Idea,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56509172/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com