我想從另一個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.