users@jersey.java.net

[Jersey] Re: Getting confused with EJB injection

From: Antonio Goncalves <antonio.mailing_at_gmail.com>
Date: Fri, 21 Jan 2011 12:26:44 +0100

Thanks for your reply. It makes more sense now.

But I still think a matrix would help ;o)

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")
> *_at_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")
> *_at_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