users@jersey.java.net

Re: Inject Stateless Bean in jersey web resource

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Thu, 24 Apr 2008 15:27:37 +0200

Hi Farjola,

[just emailing the users list]

Marc Hadley wrote:
> Injection of EJBs isn't currently supported. We plan to add such support
> in the future but for now you'll have to fall back to JNDI lookup instead.
>

I have not tried it but should possible if you don't mind depending on
Spring, see Martin's blog [1] and my blog [2].

We plan to get Spring support into the 0.8 stable build. In the mean
time you could create your own Servlet as shown in the blogs or take
code from the branch.

Paul.

[1]
http://www.javakaffee.de/blog/2008/04/21/jersey-spring-integration-mostly-complete/
[2] http://blogs.sun.com/sandoz/entry/integrating_jersey_and_spring_take

> Marc.
>
> On Apr 24, 2008, at 7:33 AM, Persa Zaloshnja wrote:
>
>> Hi all,
>>
>> I am creating a stateless bean using EJB3.0 and I'd like to inject
>> that in jersey web resource. If I inject an ejb to an http/sip
>> servlet, it works fine; but when I try the same in a jersey web res,
>> it throws a nullpointer exception. A snippet of code for example:
>>
>>
>> @Path("/helloworld")
>> public class HelloWorldBean {
>>
>> //HERE INJECTING THE BEAN USING ANNOTATIONS.
>> @EJB(name="ejb/mrbean")
>> private IMrBean bean;
>>
>>
>> @GET
>> @ProduceMime("text/html")
>> public String getClichedMessage() {
>> //WHEN CALL FUNCTION getHello() - NULLPOINTER EXCEPTION THROWN!!!
>> return bean.getHello();
>> }
>>
>> (the packaging to deploy in glassfish is done in a .ear - jersey web
>> resource in .war file and ejb in a .jar file)
>>
>> Is there anyone who has tried the same, is it possible to inject
>> 'anything' to a jersey web resource ?
>>
>>
>> Thank you in advance,
>> Farjola
>>
>>
>>
>>
>> Get news, entertainment and everything you care about at Live.com.
>> Check it out!
>
> ---
> Marc Hadley <marc.hadley at sun.com>
> CTO Office, Sun Microsystems.
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: dev-help_at_jersey.dev.java.net
>

-- 
| ? + ? = To question
----------------\
    Paul Sandoz
         x38109
+33-4-76188109