I’m trying to play around with EJB remote call but I’m getting an error. I have a web app called CallerApp that calls a method in another web app called RecieverApp.
In the CallerApp I have a remote interface:
@Remote
public interface ControllerRemote {
public int perform(int i);
}
and the call is performed in this class:
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 is depoloyed on the same Glassfish server:
@Stateless
public class Controller implements Serializable, ControllerRemote{
@Override
public int perform(int i){
//return something
}
}
The interface in RecieverApp is exactly as the one in CallerApp:
@Remote
public interface CallerRemote{
public int perform(int i);
}
I’m getting the following exception:
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]]
What I’m doing wrong here?
PS: I’m using Glassfish 3.1 and both applications are deployed on the same server.
There are few things to consider:
asadmin list-jndi-entriesCallerRemoteinterfaces are in same packages in both applications@EJB) and JNDI lookup, if your classTalkeris container-managed (i.e. bean, servlet, etc.) then@EJBannotation will suffice, otherwise use only lookup