2010-09-03 61 views
2

我想使用两个独立的服务器,一个用于web容器,一个用于ejb容器。 这两个容器都是Glassfish V3。从另一个Glassfish(Web容器)访问在另一个Glassfish(EJB容器)中运行的远程EJB

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

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

感谢

+0

可能重复[我如何可以部署会话Bean与另一台计算机与客户端JSP/Servlet](http://stackoverflow.com/questions/3614802/how-can-i-deploy-session-bean-on -otherother-computer-with-client-jsp-servlet) – 2010-09-04 20:01:56

+0

检查出来 - 完整的示例:http://stackoverflow.com/questions/4763960/accessing-a-无状态的EJB-从-另一个实例-的-的GlassFish/10194057#10194057 – 2012-04-17 18:09:26

回答

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中,假设 “com.acme.FooRemoteBusiness” 的全局JNDI名称:

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

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

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

    FooHome fooHome = (FooHome) PortableRemoteObject.narrow(obj, FooHome.class);