2014-07-14 34 views
0

我想从另一个GlassFish Server 4.0中访问@Remote bean。我尝试了很多方法,但没有人工作。从B GlassFish 4.0访问GlassFish 4.0中的远程Bean错误javaee7

//This is the remote Interface For server A and client B: 
@Remote 
public interface SayHelloBeanRemote extends Serializable{ 
public void test(String name); 
} 

//Impl for Client B: 
@Stateless 
public class SayHelloBean implements SayHelloBeanRemote { 

    @Override 
    public void test(String name) { 
    System.out.println("nihao"+name); 
    } 
} 

首先我写在JSF的方法管理的bean:

public void test() throws NamingException { 

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"); 
props.setProperty("org.omg.CORBA.ORBInitialHost", "192.168.1.104"); 
props.setProperty("org.omg.CORBA.ORBInitialPort", "3700"); 
InitialContext ctx = new InitialContext(props); 
SayHelloBeanRemote testRmi = (SayHelloBeanRemote) ctx.lookup("java:global/EJBRm/rmi/NewSessionBean"); 
testRmi.test("xx"); 
System.out.println("k开始连接....................."); 
} 

这是错误:

Exception in thread "main" javax.naming.NamingException: Lookup failed for 'java:global/EJBRmi/rmi/NewSessionBean' in SerialContext[myEnv={org.omg.CORBA.ORBInitialPort=3700, java.naming.factory.initial=com.sun.enterprise.naming.SerialInitContextFactory, org.omg.CORBA.ORBInitialHost=192.168.1.104, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.NameNotFoundException: rmi]

然后我尝试使用sun-web.xml配置的应用:

<glassfish-web-app error-url=""> 
    <ejb-ref> 
    <ejb-ref-name>RemoteEJBName</ejb-ref-name> 
    <jndi-name>corbaname:iiop:<servername or IP>:3700#java:global/Rmi_ejb /FooClassImpl!com.test.foo.FooClass</jndi-name> 
    </ejb-ref> 
</glassfish-web-app> 

我用标签:

@EJB(name="TheRef") SayHelloBeanRemote testRmi; 

但是注射失败。

所以我需要你的帮助,给访问A和B.

回答

0

之间的EJB正道既然你使用的是Java EE 7和您的服务器和客户机是在应用服务器中,没有必要做一个手动查找 - 你只需要当有一个独立的Java客户端需要访问一个EJB(请参阅我的示例my answer to this post)。

如果您从另一个托管组件访问一个EJB,只需使用注入机制即可。请参阅Java EE教程中的“Accessing Enterprise Beans”一章。

相关问题