从另一个Glassfish(Web容器)访问另一个Glassfish(EJB-Container)中运行的远程EJB

时间:2010-09-03 14:02:16

标签: glassfish ejb

我想使用两个独立的服务器,一个用于web容器,另一个用于ejb-container。 这两个容器都是Glassfish V3。

但是,如何在我的web项目中使用@EJB注释来访问远程ejb-container的ejb(s)。

在Ejb 2.0中,我们必须使用ejb-descriptors,但在Ejb3.0和glassfish v3中发生了什么?

感谢

1 个答案:

答案 0 :(得分:2)

我从来没有亲自这样做,因为我更喜欢在同一个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名称。

EJB 3.x,假设全局JNDI名称为“com.acme.FooRemoteBusiness”:

 FooRemoteBusiness foo = (FooRemoteBusiness) ic.lookup("com.acme.FooRemoteBusiness");

EJB 2.x,假设全局JNDI名称为“com.acme.FooHome”:

Object obj = ic.lookup("com.acme.FooHome");

  FooHome fooHome = (FooHome) PortableRemoteObject.narrow(obj, FooHome.class);
相关问题