【问题标题】:How to call remote EJB from standalone client如何从独立客户端调用远程 EJB
【发布时间】:2010-09-22 13:42:46
【问题描述】:

我的 EJB 部署在 weblogic 服务器上。我想从独立应用程序(瘦客户端)访问这些 EJB。

【问题讨论】:

    标签: web-applications jakarta-ee


    【解决方案1】:

    好的...我自己找到了。 :)

    这是我用来从瘦客户端连接到远程 EJB 的代码。

     Hashtable env = new Hashtable(5);
     env.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
     //Assuming weblogic server is running on localhost at port 7001
     env.put(Context.PROVIDER_URL, "t3://localhost:7001");
    
     Context ic = new InitialContext(env);
    
     //obtain a reference to the home or local home interface
     FooHome fooHome = (FooHome)ic.lookup("MyBeans/FooHome");
    
     //Get a reference to an object that implements the beans remote (component) interface
     Foo foo = fooHome.create();
    
     //call the service exposed by the bean
     foo.shoutFoo()
    

    它对我有用。

    【讨论】:

    • 如果这对你有用,你应该接受你自己的答案。
    • 如果你使用weblogic.jndi.WLInitialContextFactory这意味着你必须只从客户端调用你的EJB,获取一些weblogic库,这可能不是那么薄。
    • 你应该在 finally 块中关闭初始上下文
    • 我从命令行 java 程序 (public static void main) 运行的上述代码,我得到以下错误。请建议。线程“主”javax.naming.NoInitialContextException 中的异常:无法实例化类:weblogic.jndi.WLInitialContextFactory [根异常是 java.lang.ClassNotFoundException:weblogic.jndi.WLInitialContextFactory] ​​原因:java.lang.ClassNotFoundException:weblogic.jndi。 WLInitialContextFactory
    猜你喜欢
    • 2013-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多