2017-07-15 124 views
0

我有一個無狀態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

+0

有加GF客戶端和的appserv-rt.jar中的類路徑,但沒有工作 –

回答

1

在context.lookup只是通過完全限定接口名稱:

client.cart=(ShoppingCart)context.lookup("com.java.stateless.Calculator"); 
+0

仍然沒有工作 –

+0

你可以看到JNDI主菜爲您的EJB?請按照以下步驟檢查您的ejb是否在您的玻璃魚服務器的JNDI樹中列出。如果條目在那裏,你應該能夠查看它。你的代碼似乎是正確的。 https://docs.oracle.com/cd/E26576_01/doc.312/e24938/list-jndi-entries.htm#GSRFM00178 –

+0

我在啓動服務器時可以看到日誌中的jndi名稱:EJB的可移植JNDI名稱ShoppingCartBean:[java:global/EJBProjectOneEAR/EJ BProjectOne/ShoppingCartBean,java:global/EJBProjectOneEAR/EJBProjectOne/Shoppin gCartBean!org.jboss.tutorial.stateful.bean.ShoppingCart] |#]但是當我做list- JNDI條目 –

相關問題