【问题标题】:javax.naming.NamingException: Lookup failed - Intellij Ideajavax.naming.NamingException:查找失败 - Intellij Idea
【发布时间】: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


【解决方案1】:

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

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

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

【讨论】:

  • 参考我指定的链接和paisanco指定的链接。否则附加您的部署描述符和其他配置文件以解决问题。
  • 这是我们大约 50 年前进行 JNDI 查找的方式。 OP 正在使用现代服务器实现。
猜你喜欢
  • 1970-01-01
  • 2016-05-11
  • 1970-01-01
  • 2016-03-17
  • 2014-06-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-09-24
相关资源
最近更新 更多