【问题标题】:JNDI lookup failed on GlassFish 5GlassFish 5 上的 JNDI 查找失败
【发布时间】:2019-07-22 11:51:40
【问题描述】:

我是 Java EE 新手,我的问题可能看起来很愚蠢。

当我尝试在 Glassfish 上部署我的应用程序时,我有 javax.naming.NameNotFoundException。当我在 DeviceStorage 类中实现 java.util.Observer 时会发生这种情况。当我不这样做时,它会毫无错误地部署。有人知道为什么会发生这种情况吗?

Exception while deploying the app [Test-1.0-SNAPSHOT] : JNDI lookup 
failed for the resource: Name: 
[java:module/env/com.view.servlet.TestServlet/deviceStorage], Lookup: 
[com.core.DeviceStorage#com.core.DeviceStorage], Type: [Session].

Caused by: 
javax.naming.NameNotFoundException: 
com.core.DeviceStorage#com.core.DeviceStorage not found
@Singleton
public class ServersStateListener extends Observable {
...
}
@Singleton
public class DeviceStorage implements Observer{
...
}
@WebServlet("/test")
public class TestServlet extends HttpServlet {

    @EJB
    private ServersStateListener serversStateListener;

    @EJB
    private DeviceStorage deviceStorage;

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("--== Servlet ==--");

        System.out.printf("ServerStateListener: %s\n", serversStateListener);
        System.out.printf("DeviceStorage: %s\n", deviceStorage);

    }
}

【问题讨论】:

    标签: java ejb jndi enterprise


    【解决方案1】:

    GlassFish 中存在一个导致类似错误消息的错误。该漏洞于 2018 年 2 月在 Payara(源自 GlassFish)中发现并修复,并包含在 5.182 版本中。我不知道它是否已在 GlassFish 中修复。 Payara 错误报告可以在here 找到,修复已提交here

    错误报告提到可以使用以下属性(JVM 选项)作为解决方法:

    -Ddeployment.resource.validation=false

    我不确定该设置是否也适用于 GlassFish,或者它是否特定于 Payara。但这当然值得一试。

    【讨论】:

      猜你喜欢
      • 2018-09-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-19
      • 2011-08-08
      • 2013-06-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多