We have an issue where we have a superclass with an annotation (@Resource
) and subclasses that extend that superclass are are stateless beans.
Very similar to this, if the superclass and subclass are in the same module then the resource is injected successfully. If they are in separate modules then the resource is not injected - it seems the annotation is not processed.
I've verified through reflection that the annotation is "seen" on the class, but when I step into the ResourceInjectionAnnotationParsingProcessor
, the @Resource
annotation does not show on the classes that inherit from other modules (although it does show on classes that are in the same module).
The common solution I've been seeing is to jandex
the files and set annotations="true"
but this seems to be for static modules, not other deployments such as in our case.
The other suggestion was that the modules could be missing a dependency on the annotations, but in my example all modules involved had a dependency on <module name="javax.annotation.api"/>
.
Is there any other way to make these annotations "visible" from separate deployments?
As a minimal example, if you have a superclass
import javax.annotation.Resource;
import javax.ejb.SessionContext;
public class BaseResource {
@Resource
private SessionContext sessionContext;
public String getContext() {
return "Context is " + sessionContext;
}
}
and a subclass of
import javax.ejb.Stateless;
@Stateless
public class ResourceBean extends BaseResource {
public ResourceBean() {
System.out.println(getClass().getName() + " created");
}
}
If these are in the same module, the SessionContext
is displayed. In separate modules, SessionContext
is always null
.
You could just look up the SessionContext
as a workaround. This is not an answer to your issue but you can at least get access to the SessionContext.
public SessionContext getSessionContext()
{
try
{
InitialContext ic = new InitialContext();
return (SessionContext) ic.lookup("java:comp/EJBContext");
}
catch (NamingException ex)
{
// handle exception
}
return null;
}
Excerpt from: http://javahowto.blogspot.com/2006/06/4-ways-to-get-ejbcontext-in-ejb-3.html