【问题标题】:Javax.naming.NameNotFoundException: when trying to look up the jndi name in JavaEE and WildflyJavax.naming.NameNotFoundException:尝试在 JavaEE 和 Wildfly 中查找 jndi 名称时
【发布时间】:2020-07-19 17:07:22
【问题描述】:

我正在使用 javaee 进行一些单元测试,所以我在客户端项目中尝试远程查找 jndi 名称,以便测试当然位于 ejb 中的服务,一切都很好,握手正确完成但是在测试时,我遇到了一个异常:

test.ServiceLocatorException: javax.naming.NameNotFoundException:
/phenomenon-ejb/ClientSessionBean!utilities.CllientSessionBeanRemote

这是一个显示 appname、modulename 的 sn-p,这就是我尝试查找 jndi 的方式:

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

客户代码:

public class JunitTester {

public static final String jndi = "java:global/phenomenon-ear/phenomenon-ejb/ClientSessionBean!utilities.CllientSessionBeanRemote" ;
private static CllientSessionBeanRemote getProxy() {
    return (CllientSessionBeanRemote) ServiceLocator.getInstance().getProxy(jndi);
}


@org.junit.Test
public void Test() throws NamingException {
System.out.println(JunitTester.getProxy().Verify_No_Existence("Multiskan"));}

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

【问题讨论】:

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


    【解决方案1】:

    使用您的客户端代码,我能够在 glassfish 上成功运行.... 下面是已经说过的代码

    1. 如果您可以再次测试,请告诉我确切的例外情况。
    2. 确保 Client.jar 在你的类路径中,在我的例子中是 gf-client.jar
    3. 服务器启动并运行,然后您连接客户端
    Junit
    
    package com.au.clients;
    
    import com.au.ejbs.GreetingI;
    
    import javax.naming.NamingException;
    
    public class JunitTester {
    
        public static final String jndi = "java:global/ejb3_2_ear_exploded/ejb/Greeting";
    
        private static GreetingI getProxy() throws NamingException {
            return (GreetingI) ServiceLocator.getInstance().getProxy(jndi);
        }
    
    
        @org.junit.Test
        public void Test() throws NamingException {
            System.out.println(getProxy().Verify_No_Existence("Multiskan"));
        }
    }
    
    Service locator
    
    import com.au.ejbs.GreetingI;
    
    import javax.naming.InitialContext;
    import javax.naming.NamingException;
    
    public class ServiceLocator {
    
        public static ServiceLocator getInstance()  {
            ServiceLocator serviceLocator = null;
            if(serviceLocator == null) {
                serviceLocator = new ServiceLocator();
            }
           return serviceLocator;
        }
    
        public static GreetingI getProxy(String jndi) throws NamingException {
            InitialContext context =new InitialContext();
            GreetingI greeting = context.doLookup(jndi);
            return greeting;
    
        }
    
    
    }
    
    output
    true
    
    Process finished with exit code 0
    

    【讨论】:

    • 您好,感谢您的回答,我尝试了您的解决方案,但遇到了同样的异常,我将客户端代码添加到问题中,以便您查看。
    • 您好,谢谢,我会尽快回复您
    • 是的,我在 application.xml 中找到了它,它是一样的:phenomenon-ejb.jar
    • 嘿假设您的异常仍然是: test.ServiceLocatorException: javax.naming.NameNotFoundException: /phenomenon-ejb/ClientSessionBean!utilities.CllientSessionBeanRemote 。你能检查一下你的耳朵现象-耳朵你有jar现象-ejb吗?我怀疑这可能是问题所在,请检查 ejb 的确切名称,您可以在 application.xml 中找到它的 ejb.jar 请告诉我
    • 嘿,我已经编辑了我以前的帖子 您的客户端代码在 glassfish 上看起来不错...看看谢谢您的回复。
    猜你喜欢
    • 2016-08-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-09
    相关资源
    最近更新 更多