3

我在 GlassFish 3.1 上部署了一个带有远程接口的简单会话 EJB(3.0 规范)。这是显示部署的日志片段:

INFO: Portable JNDI names for EJB RandomNumber2Bean : [java:global/RandomNumberEJB/RandomNumber2Bean, java:global/RandomNumberEJB/RandomNumber2Bean!beans.RandomNumber2]
INFO: Glassfish-specific (Non-portable) JNDI names for EJB RandomNumber2Bean : [RandomNumber2, RandomNumber2#beans.RandomNumber2]

我试图从部署在同一台机器上的 JBoss AS 7.1.1 实例上的 Servlet 调用它。以下是来自 servlet 的相关代码:

Properties props = new Properties();
props.setProperty("java.naming.factory.initial", "com.sun.enterprise.naming.impl.SerialInitContextFactory");
props.setProperty("java.naming.factory.url.pkgs", "com.sun.enterprise.naming");
props.setProperty("java.naming.factory.state", "com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl");
InitialContext initialContext = new javax.naming.InitialContext(props);
RandomNumber2 randomNumber2 = (RandomNumber2) initialContext.lookup("RandomNumber2");

但是,每当我尝试从 servlet 获取 InitialContext 来查找 bean 时,都会收到以下错误:

javax.naming.NamingException: JBAS011843: Failed instantiate InitialContextFactory com.sun.enterprise.naming.SerialInitContextFactory from classloader ModuleClassLoader for Module "deployment.RandomNumberTesterGlassfish.war:main" from Service Module Loader
at org.jboss.as.naming.InitialContextFactoryBuilder.createInitialContextFactory(InitialContextFactoryBuilder.java:64)
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:681)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:307)
at javax.naming.InitialContext.init(InitialContext.java:242)
at javax.naming.InitialContext.<init>(InitialContext.java:216)
at test.RandomNumberServlet.doGet(RandomNumberServlet.java:32)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:734)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161)
at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930)
at java.lang.Thread.run(Thread.java:722)

我已将来自 GlassFish 的客户端 jar appserv-rt.jar 和 gf-client.jar 添加到客户端 Servlet 应用程序的构建路径(我使用 Eclipse Juno 来部署它)和%JBOSS_HOME%\standalone\lib\ext目录中。

我在网上找不到任何东西,甚至提到从 JBoss AS 7.1.1 调用部署在 GlassFish 3.1 上的 EJB。在这一点上,我完全不知所措。我能够使用独立客户端调用部署在 GlassFish 上的 EJB,并且能够从独立客户端和 GlassFish 调用部署在 JBoss 上的相同 EJB。

4

3 回答 3

2

它写在日志中:“Glassfish-specific (Non-portable) JNDI names”。因此,它可能不适用于 JBoss。试试这个:

RandomNumber2 randomNumber2 = (RandomNumber2) initialContext.lookup("java:global/RandomNumberEJB/RandomNumber2Bean");
于 2012-12-10T09:47:07.560 回答
1

我认为您无法在 Jboss AppServer 中加载 GlassFish 本机库。我props.setProperty("java.naming.factory.initial", "com.sun.enterprise.naming.impl.SerialInitContextFactory");在三个 AppServer 中测试配置:GlassFish 3、Jboss 7 和 WebSphere 8。正确运行应用程序的唯一应用程序服务器是 Glassfish。(因为com.sun.enterprise.naming.impl.SerialInitContextFactory

您应该在 GlassFish 中运行您的应用程序。这是完整的配置:

        Properties props = new Properties();
        props.setProperty("java.naming.factory.initial",
                "com.sun.enterprise.naming.SerialInitContextFactory");

        props.setProperty("java.naming.factory.url.pkgs",
                "com.sun.enterprise.naming");

        props.setProperty("java.naming.factory.state",
                "com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl");

        props.setProperty("org.omg.CORBA.ORBInitialHost", "IP");
        props.setProperty("org.omg.CORBA.ORBInitialPort", "3700");

        InitialContext context = new InitialContext(props);
        RandomNumber2 randomNumber2 =(RandomNumber2)context.lookup("RandomNumber2");
于 2013-06-12T08:15:33.693 回答
0

您也可以尝试设置以下属性吗

props.setProperty("org.omg.CORBA.ORBInitialHost", "localhost");
props.setProperty("org.omg.CORBA.ORBInitialPort", "3700");
于 2012-10-04T13:02:17.807 回答