Javax.naming.NameNotFoundException 使用 Javaee 和 Wildfly9

Javax.naming.NameNotFoundException using Javaee and Wildfly9

您好,我在尝试查找 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.handleServerMessage(Protocol.java:127)
    at org.jboss.naming.remote.protocol.v1.RemoteNamingServerV1$MessageReciever.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 名称空间中:

java:global
java:jboss
java:

但是:

Only entries within the java:jboss/exported context are accessible over remote JNDI.

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

检查:Naming Subsystem ConfiguraAtion