users@jersey.java.net

Re: Injecting spring beans annotation based

From: Jo Størset <jo.storset_at_usit.uio.no>
Date: Wed, 19 Mar 2008 20:31:59 +0100

Den 19. mars. 2008 kl. 11.16 skrev Paul Sandoz:

> Martin Grotzke wrote:
>> Hi,
>> On Mon, 2008-03-17 at 14:45 +0100, Paul Sandoz wrote:
>>> Why can't the registered Spring beans be injected into other
>>> things using Spring-based mechanisms? I know that Guice has the
>>> @Injected annotation, does Spring have a similar annotation? you
>>> can probably wire things up in the app config but it is not as
>>> nice as an annotation.
>> I think in spring 2.5 annotation-based DI has been improved
>> significantly. Though, we're still using spring 2.0 and do not use
>> spring annotations for wiring up beans, so I don't know what are
>> all the
>> possibilities provided (just having a look at the spring docs shows
>> that
>> e.g. the javax.annotation.Resource is supported).
>>
>
> OK. I thought Spring provides (or was going to provide) support for
> EE5. Spring or WebBeans (preferably WebBeans) will be the way we
> support EE5/EE6 stuff for Jersey so we don't have to implement it
> ourselves.

My resources looks something like this

@Path("/units")
@Singleton
@Service
public class UnitsResource {

     private UnitDao unitDao;

     @Autowired
     public void setUnitDao(UnitDao unitDao) {
         this.unitDao = unitDao;
     }

    // dostuff

}

And then I just set spring to scan for services and manage them. It
works nicely with SpringServlet. I'm using spring 2.5, it might be
that it isn't as easy with earlier releases.

Jo