Jakarta ee 从另一个EJB访问远程EJB

Jakarta ee 从另一个EJB访问远程EJB,jakarta-ee,glassfish,ejb,remote-access,Jakarta Ee,Glassfish,Ejb,Remote Access,我目前正在尝试使用IIOP访问远程EJB,但无法使其工作。我有两个EAR文件,它们运行在两台不同的机器上。两者都使用Glassfish 4.0和JavaEE7 ExampleAR中的EJB ExampleSessionBean2应该调用ExampleAR2中EJB ExampleSessionBean3的printHello()方法。这些EJB及其部署描述符的代码如下所示: 示例SessionBean2: @Stateless @LocalBean public class ExampleSes

我目前正在尝试使用IIOP访问远程EJB,但无法使其工作。我有两个EAR文件,它们运行在两台不同的机器上。两者都使用Glassfish 4.0和JavaEE7

ExampleAR中的EJB ExampleSessionBean2应该调用ExampleAR2中EJB ExampleSessionBean3的printHello()方法。这些EJB及其部署描述符的代码如下所示:

示例SessionBean2:

@Stateless
@LocalBean
public class ExampleSessionBean2 implements ExampleSessionBean2Interface {

@EJB(lookup="java:comp/env/ejb/ExampleSessionBean3")
ExampleSessionBean3Interface bean;

 public ExampleSessionBean2() {
        // TODO Auto-generated constructor stub
    }

    @Override
    public void printHello() {
        System.out.println("Hello, here Bean2");
        bean.printHello();
    }
示例SessionBean2 ejb-jar.xml:

<display-name>ExampleEJB2</display-name>
   <enterprise-beans>
        <session>
             <ejb-name>ExampleSessionBean2</ejb-name>
            <transaction-type>Bean</transaction-type>
            <ejb-ref>
               <ejb-ref-name>ejb/ExampleSessionBean3</ejb-ref-name>
               <remote>bean.ExampleSessionBean3Interface</remote> 
            </ejb-ref>
        </session>
    </enterprise-beans>
  <ejb-client-jar>ExampleEJB2Client.jar</ejb-client-jar>
<enterprise-beans>
        <ejb>
        <ejb-name>ExampleSessionBean2</ejb-name>
        <ejb-ref>
            <ejb-ref-name>ejb/ExampleSessionBean3</ejb-ref-name>
            <jndi-name>corbaname:iiop:[IP address]:3700#java:global/ExampleEAR2/ExampleEJB3/ExampleSessionBean3!bean.ExampleSessionBean3Interface</jndi-name>
       </ejb-ref>
        </ejb>
     </enterprise-beans>
默认设置为ejb-jar.xml和glassfish-ejb-jar.xml

当我调用ExampleSessionBean2的printHello()方法时,它什么也不会发生。Eclipse中连接的状态栏在某个点停止。但是,没有显示任何例外情况。当我在本地使用它时,它是有效的

此外,我尝试将-Dorg.omg.CORBA.ORBInitialHost=[IP地址]设置为VM的参数,但没有任何更改

使用IIOP访问远程EJB的方式正确吗?注释和描述符中的更改是否正确


我还有一个问题,那就是是否还有其他可能让两个EJB进行通信,而这两个EJB不在同一个Glassfish集群中。例如,ResourceAdapter对此有用吗?或者还有其他机制吗?

只是表面上:您正在两个bean上使用
@LocalBean
。。。要远程访问的那个(Bean3?)应该被注释为
@Remote

我试图用Remote注释它的可能副本。然而,这也不起作用。此外,请注意Bean的接口已经用Remote进行了注释。
@Stateless(name="ExampleSessionBean3")
@LocalBean
public class ExampleSessionBean3 implements ExampleSessionBean3Interface {