On Jan 20, 2011, at 9:11 PM, Antonio Goncalves wrote:
> Ok. I get it. I think I'm going to write a blog with a matrix about  
> what can be injected where. I get confused sometimes.
>
> So is it true to say that, without CDI involved :
>
>
> 1) I can't inject anything into a resource
>
> @Path("/items")
> public class ItemResource {
> }
>
>
You can of course inject JAX-RS stuff in all three cases (scope  
constraints apply for @*Param)
> 2) a resource annotated with @ManagedBean can inject : Managed Beans  
> (with @Resource), EJBs (with @EJB)
>
> @Path("/items")
> @ManagedBean
> public class ItemResource {
>     @Resource MyBean myBean;
>     @EJB MyEJB myEJB;
> }
>
Yes, the same rules as that for injection on servlets should apply.  
Note that @ManagedBean does not change the life-cycle/scoping rules.
>
> 3) a resource annotated with @Stateless can inject : Managed Beans  
> (with @Resource), EJBs (with @EJB), an entity manager (with  
> @PersistenceContext), JMS factories/destination (with @Resource)
>
> @Path("/items")
> @Stateless
> public class ItemResource {
>     @Resource MyBean myBean;
>     @EJB MyEJB myEJB;
>     @PersistenceContext EntityManager em;
>     @Resource ConnectionFactory factory;
> }
>
>
Yes, same for @Singleton. The EE injection rules on EJBs are not  
affected by the @Path annotation.
Paul.