JNDI没有像预期的那样在JBoss 4上工作

时间:2014-12-08 21:25:41

标签: ejb-3.0 jndi jboss-4.0.x

我需要将.ear部署到一个遗留的JBoss应用程序,该应用程序有一个名为GateKepper的无状态会话bean。我在该应用程序的本地副本上测试它,我希望它与生产版本几乎相同。我执行查找:

   protected  GateKeeper lookupGateKeeper() {
        String gateKeeperBeanName = null;
        try {
            Properties p = getClasspathProperties();
            InitialContext ctx = new InitialContext(p);
            gateKeeperBeanName = p.getProperty("gatekeeper.name");
            return (GateKeeper) ctx.lookup( gateKeeperBeanName );
        }
        catch (IOException e) {
            throw new GateKeeperLookupException("Gatekeeper [" + gateKeeperBeanName + "] not found.", e);
        } catch (NamingException e) {
            throw new GateKeeperLookupException("Gatekeeper [" + gateKeeperBeanName + "] not found.", e);
        }
    }

其中gatekeeperBeanName是“com.xxxxx.mercury.GateKeeper”,它是远程和本地接口的完全限定类名,我在下面介绍,我插入的属性是java.naming的标准:

java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
java.naming.provider.url=jnp://localhost:1099

GateKeeper接口上的注释(com.xxxxx.mercury.GateKeeper)

@Remote
@Local
public interface GateKeeper {
    public String processRequest(String request);
}

在启动应用程序期间,会记录以下内容:

2014-12-08 15:30:53,648 DEBUG [org.jboss.naming.NamingService] (main) !Starting jboss:service=Naming
2014-12-08 15:30:53,648 DEBUG [org.jboss.naming.NamingService] (main) !System.setProperty, key=java.naming.factory.initial, value=org.jnp.interfaces.NamingContextFactory
2014-12-08 15:30:53,648 DEBUG [org.jboss.naming.NamingService] (main) !System.setProperty, key=java.naming.factory.url.pkgs, value=org.jboss.naming:org.jnp.interfaces
2014-12-08 15:30:53,655 DEBUG [org.jboss.naming.NamingService] (main) !Creating NamingServer stub, theServer=org.jnp.server.NamingServer@5f7f84e5,rmiPort=1098,clientSocketFactory=null,serverSocketFactory=org.jboss.net.sockets.DefaultSocketFactory@ad093076
2014-12-08 15:30:53,711 DEBUG [org.jboss.naming.NamingService] (main) !NamingServer stub: NamingServer_Stub[UnicastRef2 [liveRef: [endpoint:[192.168.1.109:1098,org.jboss.net.sockets.DefaultSocketFactory@ad093076](local),objID:[36e9dd2d:14a282a12d7:-7fff, 5578168918392374819]]]]
2014-12-08 15:30:53,716 DEBUG [org.jboss.naming.NamingService] (main) !Started jndi bootstrap jnpPort=1099, rmiPort=1098, backlog=50, bindAddress=/0.0.0.0, Client SocketFactory=null, Server SocketFactory=org.jboss.net.sockets.DefaultSocketFactory@ad093076
2014-12-08 15:30:53,720 DEBUG [org.jboss.naming.NamingService] (main) !InitialContext Environment:
2014-12-08 15:30:53,720 DEBUG [org.jboss.naming.NamingService] (main) !key=java.naming.factory.initial, value=org.jnp.interfaces.NamingContextFactory
2014-12-08 15:30:53,720 DEBUG [org.jboss.naming.NamingService] (main) !key=java.naming.factory.url.pkgs, value=org.jboss.naming:org.jnp.interfaces:org.jboss.naming:org.jnp.interfaces
2014-12-08 15:30:53,722 DEBUG [org.jboss.naming.NamingService] (main) !Listening on port 1099
2014-12-08 15:30:53,724 DEBUG [org.jboss.naming.NamingService] (main) !Started jboss:service=Naming

所以它看起来真的是命名服务,所以当我尝试查找GateKeeper时为什么呢?

我明白了:

com.xxxxxcorp.vas.txws.web.GateKeeperLookupException: Gatekeeper [com.xxxxx.mercury.GateKeeper] not found.

com.xxxxxcorp.vas.txws.web.TxnServlet.lookupGateKeeper(TxnServlet.java:134)
com.xxxxxcorp.vas.txws.web.TxnServlet.getGateKeeper(TxnServlet.java:119)
com.xxxxxcorp.vas.txws.web.TxnServlet.get(TxnServlet.java:66)
com.xxxxxcorp.vas.txws.web.TxnServlet.doGet(TxnServlet.java:58)
javax.servlet.http.HttpServlet.service(HttpServlet.java:697)
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:75)

显然,发生了IOException或NamingException。有没有人在命名解决方案时遇到问题,有人能发现我做错了什么吗?

修改 如果这在任何方面都很重要jboss-service.xml对NamingService有这个说法:

   <mbean code="org.jboss.naming.NamingService"
      name="jboss:service=Naming"
      xmbean-dd="resource:xmdesc/NamingService-xmbean.xml">
      <!-- The call by value mode. true if all lookups are unmarshalled using
      the caller's TCL, false if in VM lookups return the value by reference.
      -->
      <attribute name="CallByValue">false</attribute>
      <!-- The listening port for the bootstrap JNP service. Set this to -1
        to run the NamingService without the JNP invoker listening port.
      -->
      <attribute name="Port">1099</attribute>
      <!-- The bootstrap JNP server bind address. This also sets the default
      RMI service bind address. Empty == all addresses
       -->
      <attribute name="BindAddress">${jboss.bind.address}</attribute>
      <!-- The port of the RMI naming service, 0 == anonymous -->
      <attribute name="RmiPort">1098</attribute>
      <!-- The RMI service bind address. Empty == all addresses
       -->
      <attribute name="RmiBindAddress">${jboss.bind.address}</attribute>
      <!-- The thread pool service used to control the bootstrap lookups -->
      <depends optional-attribute-name="LookupPool"
         proxy-type="attribute">jboss.system:service=ThreadPool</depends>
   </mbean>

   <mbean code="org.jboss.naming.JNDIView"
        name="jboss:service=JNDIView"
        xmbean-dd="resource:xmdesc/JNDIView-xmbean.xml">
   </mbean>

1 个答案:

答案 0 :(得分:0)

我不认为使用完全限定的接口名称作为jndi字符串..在您的情况下,它应该类似于earName / GateKeeperImpl / local或GateKeeperImpl / local

另外,我不会用@Local和@Remote注释相同的界面,我相信它会引起麻烦

希望它有所帮助!