【问题标题】:EJB 3.1 remote accessEJB 3.1 远程访问
【发布时间】:2012-02-26 08:33:42
【问题描述】:

可以使用 RMI 或作为 SOAP-RESTful 端点访问 EJB。我想从另一台计算机/IP 地址访问远程 EJB,例如在独立应用程序中。我可以通过 Web 服务端点访问 EJB,但我不知道如何使用 RMI。我该如何实现这个想法。我正在使用 Glassfish 3.1。

【问题讨论】:

    标签: web-services rmi ejb-3.1


    【解决方案1】:

    查看How do I access a Remote EJB component from a stand-alone java client? 文档。代码 sn-ps 依赖于 EJB 2(Home 接口),您应该直接查找@Remote 接口。当然,它们必须在客户端可用。

    示例

    基于:Creating EJB3 Sessions Beans using Netbeans 6.1 and Glassfish:

    jndi.properties:

    java.naming.factory.initial = com.sun.enterprise.naming.SerialInitContextFactory
    java.naming.factory.url.pkgs = com.sun.enterprise.naming
    java.naming.factory.state = com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl
    org.omg.CORBA.ORBInitialHost = localhost
    org.omg.CORBA.ORBInitialPort = 3700
    

    Main.java:

    package testclient;
    
    import java.io.FileInputStream;
    import java.util.Properties;
    import javax.naming.InitialContext;
    import stateless.TestEJBRemote;
    
    public class Main {
    
        public static void main(String[] args) {
            try {
                Properties props = new Properties();
                props.load(new FileInputStream("jndi.properties"));
                InitialContext ctx = new InitialContext(props);
                TestEJBRemote testEJB = (TestEJBRemote) ctx.lookup("stateless.TestEJBRemote");
                System.out.println(testEJB.getMessage());
            } catch (NamingException nex) {
                nex.printStackTrace();
            } catch (FileNotFoundException fnfex) {
                fnfex.printStackTrace();
            } catch (IOException ioex) {
                ioex.printStackTrace();
            }
    
        }
    
    }
    

    另见

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-27
    相关资源
    最近更新 更多