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 {
}
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;
}
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;
}
Thanks
Antonio
2011/1/20 Paul Sandoz <Paul.Sandoz_at_oracle.com>
> [resend due to java.net glitch]
>
>
> On Jan 20, 2011, at 12:13 AM, Moises Lejter wrote:
>
> You could try annotating it with @ManagedBean - just to prod the runtime
>> into realizing it really does want to do injection on it ...
>>
>>
> Yes, or use CDI.
>
> By default injection of EE resources are not supported unless you turn the
> resource into a managed bean (and note that there are some constraints when
> turning a resource class into a managed bean).
>
> 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