简体   繁体   English

在GlassFish 5上JNDI查找失败

[英]JNDI lookup failed on GlassFish 5

I'm new with Java EE and my problem may seems stupid. 我是Java EE的新手,我的问题似乎很愚蠢。

I have javax.naming.NameNotFoundException when I'm trying to deploy my application on Glassfish. 尝试在Glassfish上部署应用程序时出现javax.naming.NameNotFoundException It happens when I'm implementing java.util.Observer in the DeviceStorage class. 当我在DeviceStorage类中实现java.util.Observer时,就会发生这种情况。 When I don't it deploys without any error. 当我不这样做时,它会部署而不会出现任何错误。 Anybody has an idea why it may happens? 有人知道为什么会发生吗?

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);

    }
}

There was a bug in GlassFish that caused error messages like that. GlassFish中存在一个错误,该错误导致了这样的错误消息。 The bug was found and fixed in Payara (which is derived from GlassFish) in February 2018 and included in release version 5.182. 该错误已于2018年2月在Payara(派生自GlassFish)中发现并修复,并包含在发行版5.182中。 I don't know if it was fixed in GlassFish. 我不知道它是否已在GlassFish中修复。 The Payara bug report can be found here , and the fix was committed here . 可在此处找到Payara错误报告,并在此处提交了修复程序。

The bug report mentions that the following property (JVM option) can be used as a work-around: 该错误报告提到以下属性(JVM选项)可以用作解决方法:

-Ddeployment.resource.validation=false

I'm not sure if that setting works with GlassFish, too, or if it's specific to Payara. 我不确定该设置是否也适用于GlassFish,还是特定于Payara。 But it's certainly worth a try. 但这当然值得一试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM