You can't use CDI (means @Inject
) with this setup. CDI only works with beans managed by the container which is not the case for JAX-RS resource classes (your GreetingsResource
).
JAX-RS 2.0 does not support injection of EJBs into JAX-RS components (providers, resources).
If you use @Inject
in your case the injection is provided by the HK2 dependency injection framework which isn't aware of normal CDI beans. It even shouldn't work if you use @EJB
, I don't know why it works, maybe this has to do with Java EE 7.
As it works for you there should be no problem in using @EJB
here, but there are also some alternative approaches in my response to this question.
See also: