On Jan 21, 2011, at 12:26 PM, Antonio Goncalves wrote:
> Thanks for your reply. It makes more sense now.
>
> But I still think a matrix would help ;o)
Indeed so! would you like to contribute such a matrix to the JAX-RS
1.1 section of the Jersey user guide :-)
Paul.
>
> Antonio
>
> 2011/1/21 Paul Sandoz <Paul.Sandoz_at_oracle.com>
>
> 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.
>
>
>
> --
> --
> Antonio Goncalves (antonio.goncalves_at_gmail.com)
> Software architect
>
> Web site : www.antoniogoncalves.org
> Blog: agoncal.wordpress.com
> Feed: feeds2.feedburner.com/AntonioGoncalves
> Paris JUG leader : www.parisjug.org
> LinkedIn: www.linkedin.com/in/agoncal