I’m experimenting with loading classes at run-time and I’m curious, is it possible for @EJB annotated properties to be injected when classes are loaded in this manner? The class is being loaded from a servlet using the servlet’s classloader (ChangeAwareClassLoader).
That is, if I load a class defined as
public class Foo {
@EJB
Bar bar;
}
in the servlet as follows
ClassLoader cLoader = this.getClass().getClassLoader();
c = cLoader.loadClass("Foo");
I would like for the EJB Bar to be injected.
Thanks.
EJB’s can only be injected with
@EJBinto “managed” classes. In Java EE, this basically means only into EJBs (Stateless and Stateful EJBs, Message Beans, etc.) and Servlets/Filters.Anything else (POJOs, JPA entities, etc.) will not have the resources injected, and you’ll have to use the lookup mechanism to get access to them.