【问题标题】:Javax.naming.NameNotFoundException using Javaee and Wildfly9Javax.naming.NameNotFoundException 使用 Javaee 和 Wildfly9
【发布时间】:2020-07-22 13:49:51
【问题描述】:

您好,我在尝试查找 jndi 名称以便使用 Wildfly9 服务器在我的 JavaEE 项目中进行 junit 测试时遇到此异常:

javax.naming.NameNotFoundException: phenomenon-ejb/ClientSessionBean!utilities.CllientSessionBeanRemote -- service jboss.naming.context.java.jboss.exported.phenomenon-ejb."ClientSessionBean!utilities.CllientSessionBeanRemote"
    at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:106)
    at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:207)
    at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:184)
    at org.jboss.naming.remote.protocol.v1.Protocol$1.handleServerMessage(Protocol.java:127)
    at org.jboss.naming.remote.protocol.v1.RemoteNamingServerV1$MessageReciever$1.run(RemoteNamingServerV1.java:73)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)

这是我写的junit代码:

public class JunitTester {
    
    @org.junit.Test
    public void Test() throws NamingException {
        Context ctx = new InitialContext();
        CllientSessionBeanRemote gest = (CllientSessionBeanRemote) ctx.lookup("/phenomenon-ejb/ClientSessionBean!"+ CllientSessionBeanRemote.class.getCanonicalName());
        System.out.println(gest.Verify_No_Existence("Multiskan"));
        
    
        }
    
}

这是我的 jndi.properties 文件:

java.naming.factory.url.pkgs=org.jboss.ejb.client.naming
java.naming.factory.initial=org.jboss.naming.remote.client.InitialContextFactory
java.naming.provider.url=http-remoting://localhost:8080
jboss.naming.client.ejb.context=true
jboss.naming.client.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT=false

这是我部署应用程序时控制台中显示的输出:

java:global/phenomenon-ear/phenomenon-ejb/ClientSessionBean!utilities.ClientSessionBean
    java:app/phenomenon-ejb/ClientSessionBean!utilities.ClientSessionBean
    java:module/ClientSessionBean!utilities.ClientSessionBean
    java:global/phenomenon-ear/phenomenon-ejb/ClientSessionBean!utilities.CllientSessionBeanRemote
    java:app/phenomenon-ejb/ClientSessionBean!utilities.CllientSessionBeanRemote
    java:module/ClientSessionBean!utilities.CllientSessionBeanRemote
    java:global/phenomenon-ear/phenomenon-ejb/ClientSessionBean!utilities.CllientSessionBeanLoacal
    java:app/phenomenon-ejb/ClientSessionBean!utilities.CllientSessionBeanLoacal
    java:module/ClientSessionBean!utilities.CllientSessionBeanLoacal

顺便说一下,握手是正确完成的,我唯一的问题是如何知道 jndiname 或者为什么服务器无法识别我写的那个:

INFO: JBoss Remoting version 4.0.5.Beta1
juil. 22, 2020 2:08:34 PM org.jboss.ejb.client.remoting.VersionReceiver handleMessage
INFO: EJBCLIENT000017: Received server version 2 and marshalling strategies [river]
juil. 22, 2020 2:08:34 PM org.jboss.ejb.client.remoting.RemotingConnectionEJBReceiver associate
INFO: EJBCLIENT000013: Successful version handshake completed for receiver context EJBReceiverContext{clientContext=org.jboss.ejb.client.EJBClientContext@757942a1, receiver=Remoting connection EJB receiver [connection=Remoting connection <260479b4>,channel=jboss.ejb,nodename=desktop-k8fvkco]} on channel Channel ID a12ae3eb (outbound) of Remoting connection 651ca769 to localhost/127.0.0.1:8080

任何建议都会有所帮助,谢谢。

【问题讨论】:

    标签: wildfly jndi wildfly-9 java-ee-8


    【解决方案1】:

    Wildfly 命名子系统将条目绑定到以下全局 JNDI 命名空间:

    java:global
    java:jboss
    java:
    

    但是:

    只能访问 java:jboss/exported 上下文中的条目 通过远程 JNDI。

    确保您的业务对象使用@Remote 注释“正确公开”。

    检查:Naming Subsystem ConfiguraAtion

    【讨论】:

    • 你好,谢谢你的回答,我两天前解决了这个问题,我注意到我没有在远程界面中添加远程注释,我忘了把答案放在stackoverflow中。很好的答案兄弟,我真的很惊讶你怎么知道远程答案。太棒了!!
    • @MRSkan 谢谢,很高兴你得到它!恭喜!
    猜你喜欢
    • 1970-01-01
    • 2011-04-24
    • 1970-01-01
    • 2012-06-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-23
    相关资源
    最近更新 更多