远程EJB调用类未找到异常

far*_*eed 1 jsf ejb-3.0

我正在尝试使用EJB远程调用,但是我收到了一个错误.我有一个名为的Web应用程序调用CallerApp另一个名为的Web应用程序中的方法RecieverApp.

CallerApp我有一个远程接口:

@Remote
public interface ControllerRemote {
    public int perform(int i);
}
Run Code Online (Sandbox Code Playgroud)

并且在此课程中执行调用:

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);
 }

}
Run Code Online (Sandbox Code Playgroud)

RecieverApp在同一个Glassfish服务器上被拆除:

@Stateless
public class Controller implements Serializable, ControllerRemote{


   @Override
   public int perform(int i){
      //return something
   }
}
Run Code Online (Sandbox Code Playgroud)

RecieverApp中的界面与CallerApp中的界面完全相同:

@Remote
public interface CallerRemote{

   public int perform(int i);

}
Run Code Online (Sandbox Code Playgroud)

我收到以下异常:

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]]
Run Code Online (Sandbox Code Playgroud)

我在这里做错了什么?

PS:我正在使用Glassfish 3.1,两个应用程序都部署在同一台服务器上.

Mil*_*kic 6

有几件事要考虑:

  • 检查JNDI名称java:global/RecieverApp/Controller!bean.ControllerRemote是否存在,Glassfish 2.x中有不错的JNDI浏览器,但是他们没有把它放在GF 3中(它应该在GF 4中),但你仍然有一个很好的旧命令行:asadmin list-jndi-entries
  • 检查CallerRemote两个应用程序中的接口是否在同一个包中
  • 没有必要同时执行inject(@EJB)和JNDI查找,如果你的类Talker是容器管理的(即bean,servlet等),那么@EJB注释就足够了,否则只使用查找