访问另一个Glassfish(EJB容器)中从另一个Glassfish(Web-Container)运行的远程EJB [英] Access to remote EJB running in another Glassfish(EJB-Container) from another Glassfish(Web-Container)

查看:135
本文介绍了访问另一个Glassfish(EJB容器)中从另一个Glassfish(Web-Container)运行的远程EJB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



但是,如何在我的Web项目中使用@EJB注释来访问远程ejb容器的ejb(在Ejb 2.0中,我们必须使用ejb描述符,但是在Ejb3.0和glassfish v3中发生了什么?



谢谢

解决方案

我从来没有亲自做过,因为我喜欢在同一个JVM中使用本地界面,因为它改善



但您可以查看以下内容:



https://glassfish.dev.java.net/javaee5/ejb/EJB_FAQ.html#StandaloneRemoteEJB



但是你可以尝试一下:

 属性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);


//可选。默认为localhost。只需要web服务器在不同的主机上运行
//而不是appserver
props.setProperty(org.omg.CORBA.ORBInitialHost,ejb_server_ip_or_host_name);

//可选。默认为3700.只有当目标orb端口不是3700时才需要。
props.setProperty(org.omg.CORBA.ORBInitialPort,3700);

InitialContext ic = new InitialContext(props);

步骤2.在查找中使用目标Remote 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);


I want to use two separate servers, one for web-container and one for ejb-container. The both of these two containers are Glassfish V3.

But, How to use @EJB annotation in my web project to access to remote ejb-container's ejb(s).

In Ejb 2.0 we have to use ejb-descriptors but what happened in Ejb3.0 and glassfish v3?

thanks

解决方案

I've never personally done that because I prefer using local interfaces within the same JVM as it improves performance dramatically.

But you can check this out:

https://glassfish.dev.java.net/javaee5/ejb/EJB_FAQ.html#StandaloneRemoteEJB

But you can give this a try:

    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);

Step 2. Use the global JNDI name of the target Remote EJB in the lookup.

EJB 3.x, assuming a global JNDI name of "com.acme.FooRemoteBusiness" :

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

EJB 2.x, assuming a global JNDI name of "com.acme.FooHome" :

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

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

这篇关于访问另一个Glassfish(EJB容器)中从另一个Glassfish(Web-Container)运行的远程EJB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆