users@jersey.java.net

Re: [Jersey] Inject EJB into resource class

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Fri, 28 Aug 2009 13:19:02 +0200

Hi Zach,

On Aug 27, 2009, at 4:36 PM, Zach Cox wrote:

> I take that back - it's not working fine. My stateless session
> bean/resource class has this injected field:
>
> @PersistenceContext(unitName = "myPU")
> private EntityManager manager;
>
> This EntityManager gets injected when my bean is injected into a JSF
> managed bean, but it does not get injected when my bean is used as a
> Jersey resource. Is this why GlassFish v3 Preview is required?
>

You need to use GF preview or greater (more specifically build 42 of
v3 or greater), see here:

   http://blogs.sun.com/sandoz/entry/glassfish_v3_ejb_3_1

The @Stateless annotation will be ignored if deployed on prelude,
which is why injection is not working as the EJB 3.1 container was not
implemented in Prelude.

Note that Jersey now ships with GF v3 builds, currently in the latest
builds it is 1.1.1-ea, and for the milestone released next Monday
Jersey 1.1.2-ea will be integrated.

See also the following EJB sample:

   http://download.java.net/maven/2/com/sun/jersey/samples/jersey-ejb/1.1.2-ea/jersey-ejb-1.1.2-ea-project.zip

Note that as per the README.html this sample is only guaranteed to
full work as implemented for GlassFish v3 build 58 or later.

You can get the latest promoted build here:

   http://download.java.net/glassfish/v3/promoted/

Build 61 is the latest:

   http://download.java.net/glassfish/v3/promoted/glassfish-v3-preview-b61.zip

Paul.

>
> On Thu, Aug 27, 2009 at 10:20 AM, Zach Cox<zcox522_at_gmail.com> wrote:
>> Hi Paul,
>>
>>> 2) Make PicturesResource a stateless or singleton bean and
>>> resource. You
>>> need to use a version of GlassFish that is equal to or greater
>>> than preview.
>>
>> I really like this approach: by adding JAX-RS annotations to a
>> stateless session bean you end up being able to reuse your business
>> logic by 1) injecting that bean into other things like a JSF managed
>> bean, and 2) exposing it as a RESTful web service.
>>
>> I'm using the latest GlassFish Tools Bundle for Eclipse v1.1 that
>> includes a bundled GlassFish v3 Prelude, and everything seems to be
>> working fine. Is there something specifically in GlassFish v3
>> Preview
>> I should be aware of, that's not in Prelude?
>>
>> Thanks,
>> Zach
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>