JavaアプリケーションクライアントからEJBのメソッドを呼び出そうとして問題が発生しました。これがコードです。
EJBリモートインターフェース
package com.test;
import javax.ejb.Remote;
@Remote
public interface HelloBeanRemote {
public String sayHello();
}
EJB
package com.test;
import javax.ejb.Stateless;
@Stateless (name="HelloBeanExample" , mappedName="ejb/HelloBean")
public class HelloBean implements HelloBeanRemote {
@Override
public String sayHello(){
return "hola";
}
}
メインクラス(別のプロジェクト)
import com.test.HelloBeanRemote;
import javax.naming.Context;
import javax.naming.InitialContext;
public class Main {
public void runTest()throws Exception{
Context ctx = new InitialContext();
HelloBeanRemote bean = (HelloBeanRemote)ctx.lookup("java:global/Test/HelloBeanExample!com.test.HelloBeanRemote");
System.out.println(bean.sayHello());
}
public static void main(String[] args)throws Exception {
Main main = new Main();
main.runTest();
}
}
さて、私の問題は何ですか?このEJBのJNDIエントリが見つかりません!
java.lang.NullPointerException
at com.sun.enterprise.naming.impl.SerialContext.getRemoteProvider(SerialContext.java:297)
at com.sun.enterprise.naming.impl.SerialContext.getProvider(SerialContext.java:271)
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:430)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at testdesktop.Main.runTest(Main.java:22)
at testdesktop.Main.main(Main.java:31) Exception in thread "main" javax.naming.NamingException: Lookup failed for 'java:global/Test/HelloBeanExample!com.test.HelloBeanRemote' in SerialContext [Root exception is javax.naming.NamingException: Unable to acquire SerialContextProvider for SerialContext [Root exception is java.lang.NullPointerException]]
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:442)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at testdesktop.Main.runTest(Main.java:22)
at testdesktop.Main.main(Main.java:31) Caused by: javax.naming.NamingException: Unable to acquire SerialContextProvider for SerialContext [Root exception is java.lang.NullPointerException]
at com.sun.enterprise.naming.impl.SerialContext.getProvider(SerialContext.java:276)
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:430)
... 3 more Caused by: java.lang.NullPointerException
at com.sun.enterprise.naming.impl.SerialContext.getRemoteProvider(SerialContext.java:297)
at com.sun.enterprise.naming.impl.SerialContext.getProvider(SerialContext.java:271)
... 4 more Java Result: 1
さまざまなJNDIエントリを試しましたが、何も機能しません(NetBeansコンソールからこのエントリを取得しました)。
情報:EJB HelloBeanExampleのポータブルJNDI名:[java:global / Test / HelloBeanExample、java:global / Test / HelloBeanExample!com.test.HelloBeanRemote]
情報:EJB HelloBeanのGlassfish固有の(移植性のない)JNDI名例:[ejb / HelloBean、ejb / HelloBean#com.test.HelloBeanRemote]
だから私は次のエントリで試しましたが、同じ例外が発生しました:
- java:global / Test / HelloBeanExample
- java:global / Test / HelloBeanExample!com.test.HelloBeanRemote
- ejb / HelloBean
- ejb / HelloBean#com.test.HelloBeanRemote
Netbeans6.8とGlassfishv3を使用しています。