users@jersey.java.net

[Jersey] Re: Getting confused with EJB injection

From: Antonio Goncalves <antonio.mailing_at_gmail.com>
Date: Sat, 22 Jan 2011 13:04:58 +0100

Actually I was more thinking of a Java EE 6 matrix (not just JAX-RS). But if
it's complete and accurate enough, yes, why not having it on other
specifications.

These are the EE 6 components that I see from the top of my head that can
benefit (or not) from injection (I'm sure I'm missing some, I need to
investigate a bit more) :

POJO
ManagedBean
Interceptor
Entity
Stateless
Singleton
Stateful
MDB
Servlet
ServletFilter
JSF backing beans
REST service
SOAP service

Then, there are some important services that can be injected (or not) in
these components (again, I have to investigate a bit more) :

EntityManager
JMS Factory/Destination
DataSource
Environment entries
UserTransaction
TimerService

What if I start a page on Wikipedia so that people can add/update
information ?

Antonio

2011/1/21 Paul Sandoz <Paul.Sandoz_at_oracle.com>

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


-- 
--
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