我想使用两个独立的服务器,一个用于web容器,另一个用于ejb容器。这两个容器都是Glassfish V3。
但是,如何在我的web项目中使用@EJB注释来访问远程ejb容器的ejb。
在EJB2.0中,我们必须使用Ejb描述符,但是在Ejb3.0和glassfish v3中发生了什么呢?
谢谢
发布于 2010-09-24 08:58:03
我个人从来没有这样做过,因为我更喜欢在同一个JVM中使用本地接口,因为它可以显着提高性能。
但你可以看看这个:
https://glassfish.dev.java.net/javaee5/ejb/EJB_FAQ.html#StandaloneRemoteEJB
但你可以试一试:
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");
// optional. Defaults to localhost. Only needed if web server is running
// on a different host than the appserver
props.setProperty("org.omg.CORBA.ORBInitialHost", "ejb_server_ip_or_host_name");
// optional. Defaults to 3700. Only needed if target orb port is not 3700.
props.setProperty("org.omg.CORBA.ORBInitialPort", "3700");
InitialContext ic = new InitialContext(props);步骤2.在查找中使用目标远程EJB的全局JNDI名称。
EJB3.x,假设全局JNDI名称为"com.acme.FooRemoteBusiness“:
FooRemoteBusiness foo = (FooRemoteBusiness) ic.lookup("com.acme.FooRemoteBusiness");EJB2.x,假设全局JNDI名称为"com.acme.FooHome“:
Object obj = ic.lookup("com.acme.FooHome");
FooHome fooHome = (FooHome) PortableRemoteObject.narrow(obj, FooHome.class);https://stackoverflow.com/questions/3636507
复制相似问题