【问题标题】:Remote EJB call class not found exception找不到远程 EJB 调用类异常
【发布时间】:2012-12-04 10:39:33
【问题描述】:

我正在尝试使用 EJB 远程调用,但出现错误。我有一个名为CallerApp 的网络应用程序,它调用另一个名为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,两个应用程序都部署在同一台服务器上。

【问题讨论】:

    标签: jsf ejb-3.0


    【解决方案1】:

    有几件事情需要考虑:

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

    【讨论】:

    • 完美!!正如您在第 2 点中建议的那样,它是包命名。我对接口有不同的包命名。非常感谢:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-25
    • 1970-01-01
    • 2012-11-03
    • 1970-01-01
    • 1970-01-01
    • 2014-08-18
    相关资源
    最近更新 更多