Reputation: 1138
I have an EAR application with three modules:
all are packaged in "app.ear".
This is working fine, but now I have to use the same beans outside the EAR application, and injection is not working.
I have in app-ejb:
@Stateless
@LocalBean
public class Services implements ServicesRemote {
[...]
}
and his remote interface in app-remote:
@Remote
public interface ServicesRemote {
[...]
}
In my app-war I can inject the remote bean without problem:
@Stateless
@LocalBean
public class UseServices {
@EJB
private ServicesRemote services;
[...]
}
Anyway in my external ejb application, deployed as stand-alone and using the same ejb-remote as library, if I try to inject the same EJB like this:
@Stateless
@LocalBean
public class UseServicesFromAnotherApp {
@EJB
private ServicesRemote services;
[...]
}
Glassfish (4.1) give me an error "Class [ Lcom/[...]/ServicesRemote; ] not found".
Is this expected? How can I inject the remote bean correctly?
Upvotes: 1
Views: 1240
Reputation: 1138
The problem was probably generated by a number of hot deploys, made glassfish unstable. When I restarted glassfish my code start to work properly (it's actually still working).
Sorry for posting here without trying to restart glassfish first.
Upvotes: 1
Reputation: 595
Injection doesn't work with remote interfaces. Beans that are "injectable", live inside container's JVM and are available for injection to other beans inside the same application. The same holds true for accessing beans in another application in the same container, although applications may live in the same JVM. Since remote methods are originated from another JVM or another application, injection is not possible. You must use JNDI lookup instead to get a reference to a remote bean.
As a matter or personal taste, I would stay away from EJB Remote interfaces, and instead I would use another "remoting" technique such as REST.
Upvotes: 2