I've got an ear with the following structure:
- app-ear
- app-api
- app-ejb
- app-web
The app-web and app-ejb depends on the app-api module, but they are not depending on each other.
The interfaces (app-api) and the bean (app-ejb):
package sample.services;
@Remote
public interface SampleServiceRemote{
...
}
package sample.services;
@Local
public interface SampleService extends SampleServiceRemote{
...
}
package sample.services;
@Stateless
@Local(SampleService.class)
@Remote(SampleServiceRemote.class)
public class SampleServiceBean implements SampleService{
...
}
I want to lookup for the SampleServiceBean with Local and Remote interface from the app-api and app-web modules:
InitialContext ic = new InitialContext();
//Case #1: Works fine without any exception
SampleServiceRemote service = (SampleServiceRemote) ic.lookup("java:global/app-ear/app-ejb/SampleServiceBean!sample.services.SampleServiceRemote");
//Case #2: Throws ClassCastException
SampleService service = (SampleService) ic.lookup("java:global/app-ear/app-ejb/SampleServiceBean!sample.services.SampleService");
When I lookup with the local interface on a WildFly server (9.0.1.Final), it gives back a sample.services.SampleService$$$view4 object, which cannot be casted to SampleService.
I tried the same application on Glassfish 4.1, but there it is working pretty well. The returned objects:
- Remote: javax.naming.Reference (castable to SampleServiceRemote)
- Local: com.sun.ejb.containers.JavaGlobalJndiNamingObjectProxy (castable to SampleService)
Can somebody tell me, how can I achieve the same behavior on WildFly?
Update 1
I tried the solution recommended by user140547. It didn't work. It gives back the same classes :/.
Update 2
After several days of trying, and Googleing I decided to exclude the EJB from my project. They are not necessary, and I can do the without them. The problem was, when I tried to use the bean as Local, the Wildfly always gave me some Proxy class, which cannot be casted to the Local interface (neither to the Remote interface). I can get Local reference only with the @EJB annotation, but outside of the EJB module it gave back only a null :/.