我有一個無狀態BeanEJB遠程客戶端拋出NullPointerException異常:無法獲取SerialContextProvider
@Stateless
public class CalculatorImpl implements Calculator {
private static final long serialVersionUID = 1L;
@Override
public int add(int a, int b) {
return a+b;
}
@Override
public int sub(int a, int b) {
return a-b;
}
@Override
public int mul(int a, int b) {
return a*b;
}
@Override
public float div(int a, int b) {
return a/b;
}
}
我已經當我試圖訪問與@Remote
@Remote
public interface Calculator extends Serializable{
public int add(int a, int b)throws RemoteException;
public int sub(int a, int b)throws RemoteException;
public int mul(int a, int b)throws RemoteException;
public float div(int a, int b)throws RemoteException;
}
註釋界面來部署這個在GlassFish它由客戶端即一個Java桌面應用程序: 它是拋出一個NullpointerException
客戶端代碼:
MyClient client= new MyClient();
Properties props = new Properties();
props.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.enterprise.naming.SerialInitContextFactory");
props.setProperty("org.omg.CORBA.ORBInitialHost", "localhost");
// glassfish default port value will be 3700,
// but im using tcpviewer to redirect my 50005 port to 3700
props.setProperty("org.omg.CORBA.ORBInitialPort", "3700");
InitialContext context = new InitialContext(props);
client.cart = (ShoppingCart) context
.lookup("java:global/EJBDemo2EAR/EJBDemo2/CalculatorImpl!com.java.stateless.Calculator");
System.out.println("In doget");
client.cart.buy("soap", 12);
client.cart.getCartContents();
錯誤是: 顯示java.lang.NullPointerException 在com.sun.enterprise.naming.impl.SerialContext.getORB(SerialContext.java:347) 在com.sun.enterprise.naming.impl。 SerialContext.getProviderCacheKey(SerialContext.java:354) at com.sun.enterprise.naming.impl.SerialContext.getRemoteProvider(SerialContext.java:384) at com.sun.enterprise.naming.impl.SerialContext.getProvider(SerialContext。 java:329) at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:477) at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:438) at javax.naming.InitialContext.lookup(InitialContext.java:417) at com.java.client.MyClient.main(MyClient.java:30) 線程「main」中的異常javax.naming.NamingException:查找失敗在SerialContext中的'java:global/EJBDemo2EAR/EJBDemo2/CalculatorImpl!com.java.stateless.Calculator'[myEnv = {org.omg.CORBA.ORBInitialPort = 3700,java.naming.factory.initial = com.sun.enterprise.naming .SerialInitContextFactory,org.omg.CORBA.ORBInitialHost = localhost,java.naming.factory.url.pkgs = com.sun.enterprise.naming,java.naming.factory.state = com.sun.corba.ee.impl.presentation .rmi.JNDIStateFactoryImpl} [根異常是javax.naming.NamingException:無法獲取SerialContext的SerialContextProvider [myEnv = {org.omg.CORBA.ORBInitialPort = 3700,java.naming.factory.initial = com.sun.enterprise.naming .SerialInitContextFactory,org.omg.CORBA.ORBInitialHost = localhost,java.naming.factory.url.pkgs = com.sun.enterprise.naming,java.naming.f actory.state = com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl} [根異常是顯示java.lang.NullPointerException]] 在com.sun.enterprise.naming.impl.SerialContext.lookup
有加GF客戶端和的appserv-rt.jar中的類路徑,但沒有工作 –