Jsf 未找到远程EJB调用类异常

Jsf 未找到远程EJB调用类异常,jsf,ejb-3.0,Jsf,Ejb 3.0,我正在尝试使用EJB远程调用,但遇到了一个错误。我有一个名为CallerApp的web应用程序,它调用另一个名为RecieverApp的web应用程序中的方法 在CallerApp中,我有一个远程接口: @Remote public interface ControllerRemote { public int perform(int i); } 并且在该类中执行调用: public class Talker { @EJB private ControllerRemote re

我正在尝试使用EJB远程调用,但遇到了一个错误。我有一个名为
CallerApp
的web应用程序,它调用另一个名为
RecieverApp
的web应用程序中的方法

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,两个应用程序都部署在同一台服务器上。

有几件事需要考虑:

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

    • 需要考虑的事情很少:

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

      完美!!这是u在第2点中建议的包命名。我对接口有不同的包命名。非常感谢:)太好了!!这是u在第2点中建议的包命名。我对接口有不同的包命名。非常感谢:)