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