1

EJB リモート呼び出しを試してみましたが、エラーが発生しました。というCallerApp別の Web アプリのメソッドを呼び出す という Web アプリがありRecieverAppます。

CallerApp私はリモートインターフェースを持っています:

@Remote
public interface ControllerRemote {
    public int perform(int i);
}

呼び出しはこのクラスで実行されます。

public class Talker {

   @EJB private ControllerRemote remote;

   //constructor and invoke setRemote() method to set remote

   private void setRemote() throws Exception{
        Properties p = new Properties();
        Context jndiContext = new InitialContext(p);
        Object ref = jndiContext.lookup("java:global/RecieverApp/Controller!bean.ControllerRemote");
        remote = (ControllerRemote) PortableRemoteObject.narrow(ref, ControllerRemote.class);
   }

 public void action(){
      remote.perform(5);
 }

}

RecieverApp は、同じ Glassfish サーバーにデプロイされています。

@Stateless
public class Controller implements Serializable, ControllerRemote{


   @Override
   public int perform(int i){
      //return something
   }
}

RecieverApp のインターフェイスは、CallerApp のものとまったく同じです。

@Remote
public interface CallerRemote{

   public int perform(int i);

}

次の例外が発生します。

SEVERE: javax.naming.NamingException: Lookup failed for 'java:global/RecieverApp/Controller!bean.ControllerRemote'
   in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory,
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.NamingException: ejb ref resolution error for remote business interfacebean.ControllerRemote
[Root exception is java.lang.ClassNotFoundException: bean.ControllerRemote]]

ここで何が間違っていますか?

PS: 私は Glassfish 3.1 を使用しており、両方のアプリケーションが同じサーバーにデプロイされています。

4

1 に答える 1

6

考慮すべき点がいくつかあります。

  • JNDI 名java:global/RecieverApp/Controller!bean.ControllerRemoteが存在するかどうかを確認します。Glassfish 2.x には優れた JNDI ブラウザがありましたが、GF 3 には入れられませんでした ( GF 4にあるはずです)。古き良きコマンドラインがあります:asadmin list-jndi-entries
  • CallerRemoteインターフェイスが両方のアプリケーションで同じパッケージに含まれているかどうかを確認します
  • @EJBインジェクション ( ) と JNDI ルックアップの両方を実行する必要はありません。クラスTalkerがコンテナー管理 (つまり、Bean、サーブレットなど) の場合は@EJBアノテーションで十分です。それ以外の場合はルックアップのみを使用します。
于 2012-12-04T12:47:17.090 に答える