I'm developing an REST application using Glassfish 4.0.
In resource classes I can get injection to work by making the class @Stateless and injecting via @EJB (injected class is an stateless EJB).
However this approach does not work in an JAX-RS filter. I cannot get injection to work at all.
See code below:
@Provider
public class UpdateFilter implements ContainerRequestFilter {
@EJB
private MyBeanInterface doStuffBean;
@Override
public void filter(ContainerRequestContext requestContext) {
...
}
}
doStuffBean is always null.
Any suggestions?
I believe the @EJB only works in Java EE managed classes like other EJBs and Servlets.
If you are using CDI you could use @Inject annotation instead but if this class is not a ManagedBean then you will need to do a lookup.
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