我有一个无国籍的ejb。
@Remote
public interface MyService {
...
}
impl
@Stateless
public class MyServiceImpl implements MyService {
...
}
我有另一个尝试使用MyService的bean,它将通过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的耳朵进行部署依赖。提供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中运行。
答案 0 :(得分: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 FAQ了解详情。