我有一个无状态的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 中运行。