1

我有一个无状态的ejb。

@Remote
public interface MyService {
   ...
}

impl

@Stateless
public class MyServiceImpl implements MyService {
  ...
}

我有另一个 bean 正在尝试使用 MyService,它将通过 JMX 公开。

@MXBean
public interface MyJMXBean {
   ...
}

@Singleton
@Startup
public class MyJMXBeanImpl implements MyJMXBean {
   @EJB
   MyService service; // this works

   @PostConstruct
   private void init() { ... }

   @PreDestroy
   private void cleanup() { ... }

   // this doesn't
   private MyService doLookup() {
      InitialContext ctx = new InitialContext();
      return (MyService) ctx.lookup(MyService.class.getName());
   }
}

我希望能够对 MyService 进行 jndi 查找,因此我没有对提供 MyService 的 ear 的部署依赖。提供 MyService 和 MyJMXBean 的耳朵不同,但部署到同一个容器。我得到的例外是:

Caused by: javax.naming.CommunicationException: Communication exception for SerialContext[myEnv={java.naming.factory.initial=com.sun.jndi.cosnaming.CNCtxFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming}
        at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:542) ~[glassfish-naming.jar:3.1.2.1-SNAPSHOT]
        at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:455) ~[glassfish-naming.jar:3.1.2.1-SNAPSHOT]
        at javax.naming.InitialContext.lookup(InitialContext.java:411) ~[na:1.7.0_15]
        at javax.naming.InitialContext.lookup(InitialContext.java:411) ~[na:1.7.0_15]
        at com.sun.ejb.containers.RemoteBusinessObjectFactory.getObjectInstance(RemoteBusinessObjectFactory.java:71) ~[ejb-container.jar:3.1.2.1-SNAPSHOT]
        at com.sun.enterprise.naming.impl.SerialContext.getObjectInstance(SerialContext.java:580) ~[glassfish-naming.jar:3.1.2.1-SNAPSHOT]
        at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:514) ~[glassfish-naming.jar:3.1.2.1-SNAPSHOT]
        ... 38 common frames omitted
Caused by: org.omg.CORBA.INITIALIZE: can't instantiate default ORB implementation com.sun.corba.ee.impl.orb.ORBImpl
        at org.omg.CORBA.ORB.create_impl(ORB.java:314) ~[na:1.7.0_15]
        at org.omg.CORBA.ORB.init(ORB.java:353) ~[na:1.7.0_15]
        at com.sun.jndi.toolkit.corba.CorbaUtils.getOrb(CorbaUtils.java:203) ~[na:1.7.0_15]
        at com.sun.jndi.cosnaming.CNCtx.getDefaultOrb(CNCtx.java:72) ~[na:1.7.0_15]
        at com.sun.jndi.cosnaming.CNCtx.initOrbAndRootContext(CNCtx.java:234) ~[na:1.7.0_15]
        at com.sun.jndi.cosnaming.CNCtx.<init>(CNCtx.java:105) ~[na:1.7.0_15]
        at com.sun.jndi.cosnaming.CNCtxFactory.getInitialContext(CNCtxFactory.java:49) ~[na:1.7.0_15]
        at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:684) ~[na:1.7.0_15]
        at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:307) ~[na:1.7.0_15]
        at javax.naming.InitialContext.init(InitialContext.java:242) ~[na:1.7.0_15]
        at javax.naming.InitialContext.<init>(InitialContext.java:216) ~[na:1.7.0_15]
        at com.sun.enterprise.naming.util.IIOPObjectFactory.getObjectInstance(IIOPObjectFactory.java:73) ~[glassfish-naming.jar:3.1.2.1-SNAPSHOT]
        at com.sun.enterprise.naming.impl.SerialContext.getObjectInstance(SerialContext.java:580) ~[glassfish-naming.jar:3.1.2.1-SNAPSHOT]
        at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:514) ~[glassfish-naming.jar:3.1.2.1-SNAPSHOT]
        ... 44 common frames omitted
Caused by: java.lang.ClassNotFoundException: com.sun.corba.ee.impl.orb.ORBImpl
        at java.net.URLClassLoader$1.run(URLClassLoader.java:366) ~[na:1.7.0_15]
        at java.net.URLClassLoader$1.run(URLClassLoader.java:355) ~[na:1.7.0_15]
        at java.security.AccessController.doPrivileged(Native Method) [na:1.7.0_15]
        at java.net.URLClassLoader.findClass(URLClassLoader.java:354) ~[na:1.7.0_15]
        at java.lang.ClassLoader.loadClass(ClassLoader.java:423) ~[na:1.7.0_15]
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) ~[na:1.7.0_15]
        at java.lang.ClassLoader.loadClass(ClassLoader.java:356) ~[na:1.7.0_15]
        at java.lang.Class.forName0(Native Method) ~[na:1.7.0_15]
        at java.lang.Class.forName(Class.java:266) ~[na:1.7.0_15]
        at org.omg.CORBA.ORB.create_impl(ORB.java:312) ~[na:1.7.0_15]
        ... 57 common frames omitted

我不太确定如何解决 ClassNotFoundException,因为一切都在 Glassfish 中运行。

4

1 回答 1

0

GlassFish V3 支持 EJB 3.1 并在 EJB 3.1 中实现可移植全局会话 bean JNDI 名称的语法,如下所示

java:global[/<app-name>]/<module-name>/<bean-name>

<bean-name>对应于会话 bean 的 EJB 名称。它默认为会话 bean 类的非限定名称。可以使用@Stateless/@Stateful/@Singleton注解的 name 属性显式指定它。

您在 JNDI 树中查找的是 EJB 类的限定名称。

您可以查看GlassFish EJB 常见问题以了解详细信息。

于 2013-03-19T21:02:20.287 回答