javacdiejb-3.2

@Inject a @Remote EJB in Web Application


Is it possibile to @Inject a @Remote EJB in a Web Application? I'm running on Glassfish 5 and I'm deploying an EAR (EJB + WAR).

When I annotate the EJB interface with @Local CDI works, with @Remote not.
What might be the cause?

By the way, using @EJB instead of @Inject works flawlessly, but I'm up to solve the @Inject issue.


Solution

  • CDI is not able to resolve remote ejb beans. As per the specs 3.2.2

    The unrestricted set of bean types for a session bean contains all local interfaces of the bean and their superinterfaces. If the session bean has a no-interface view, the unrestricted set of bean Declaring a session bean 41 types contains the bean class and all superclasses. In addition, java.lang.Object is a bean type of every session bean. Remote interfaces are not included in the set of bean types.

    What you can do is to have a field producer for the remote interfaces, if you must use CDI injections rather than @EJB