使用java进行JNDI查找:即使输出了jndi,app name也会获取NameNotFoundException

时间:2015-10-08 17:57:35

标签: eclipse jndi wildfly

我有一个ear文件,RavenWeb包含一个名为RavenWeb_Bean的ejb。当服务器启动时,它输出:

13:34:28,095 INFO  [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-1) JNDI bindings for session bean named TerminalBean in deployment unit subdeployment "RavenWeb_Bean" of deployment "RavenWeb-1.0.0-SNAPSHOT.ear" are as follows:

java:global/RavenWeb-1.0.0-SNAPSHOT/RavenWeb_Bean/TerminalBean!com.scientificgames.raven.ejb.session.TerminalBean.TerminalBeanRemote
java:app/RavenWeb_Bean/TerminalBean!com.scientificgames.raven.ejb.session.TerminalBean.TerminalBeanRemote
java:module/TerminalBean!com.scientificgames.raven.ejb.session.TerminalBean.TerminalBeanRemote
java:jboss/exported/RavenWeb-1.0.0-SNAPSHOT/RavenWeb_Bean/TerminalBean!com.scientificgames.raven.ejb.session.TerminalBean.TerminalBeanRemote
java:global/RavenWeb-1.0.0-SNAPSHOT/RavenWeb_Bean/TerminalBean!com.scientificgames.raven.ejb.session.TerminalBean.TerminalBeanLocal
java:app/RavenWeb_Bean/TerminalBean!com.scientificgames.raven.ejb.session.TerminalBean.TerminalBeanLocal
java:module/TerminalBean!com.scientificgames.raven.ejb.session.TerminalBean.TerminalBeanLocal

然而,当我在同一个项目中尝试查找时,我收到了:

13:34:51,957 ERROR [stderr](Thread-122)com.scientificgames.raven.ejb.common.CommonBeanException:javax.naming.NameNotFoundException:java:app / RavenWeb_Bean / TerminalBean!com.scientificgames.raven.ejb .session.TerminalBean.TerminalBeanLocal

与启动输出中的一行完全匹配。

我最初使用java:global来查找资源,但JBoss工具中的更改将ear文件从RavenWeb.ear重命名为RavenWeb-1.0.0.SNAPSHOT.ear,然后抛弃了查找。 我不确定除了日志消息之外还有什么附加。

编辑:经过一些调试后,我发现htat javax.naming.InitialContext.findContext()对selector.getContext()的调用返回null,这是导致引发NameNotFoundException的原因。

编辑:查找代码

public static Object getLocalBean(Class<? extends CommonBean> commonBeanClass) throws CommonBeanException
{
    try
    {
        String localInterfaceClassName = null;
        for (Class<?> implementedInterface : commonBeanClass.getInterfaces()) {
            if (implementedInterface.isAnnotationPresent(Local.class)) {
                localInterfaceClassName = implementedInterface.getName();
                break;
            }
        }
        if (localInterfaceClassName == null) {
            throw new CommonBeanException("Could not locate @Local interface for " + commonBeanClass);
        }

        return InitialContext.doLookup("java:app/RavenWeb_Bean/" + commonBeanClass.getSimpleName() + "!" + localInterfaceClassName);
    }
    catch (IllegalArgumentException e)
    {
        throw new CommonBeanException(e);
    }
    catch (NamingException e)
    {
        throw new CommonBeanException(e);
    }
    catch (SecurityException e)
    {
        throw new CommonBeanException(e);
    }
}

0 个答案:

没有答案