I'm using RestEasy in a JBoss AS 7.1.1 environment.
I implemented for security reasons a PreProcessInterceptor class. The class is annotated with @Provider and @ServerInterceptor. The interceptor is invoked everytime, which is fine.
Now, what bothers me is the following.
I inject a EJB with the @EJB annotation into the class. When the PreProcessInterceptor is called, that said EJB is always null.
@Provider
@ServerInterceptor
public class SecurityInterceptor implements PreProcessInterceptor
{
@EJB
private SomeEjb someEjbServiceFacade;
... some funny stuff
}
That EJB looks like followed:
@Stateless
public class SomeEjb extends AbstractServiceFacade
{
... some important stuff
}
The funny part, it works via lookup:
Context ctx = new InitialContext();
SomeEjb asf = ( SomeEjb )ctx.lookup("java:global/mySuperApplication/SomeEjb" );
Does someone has an explanation for this behaviour?
Thanks in advance.
You can not inject EJB in arbitrary class, but only in specified type such as Servlet, Filter, Listener, Stateless, Statefull, MessageDriven beans, Singleton. If you want to use EJB in other types of class then use access though JNDI as you pointed above.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With