javaspringapache-winkapache-wink-spring

Wink : how to use spring life cycle management?


I have a Wink application with some resources, on which I'd like to make some dependency injection of Spring beans. I defined my resource as bean following the example located here http://wink.apache.org/1.0/html/5.5%20Spring%20Integration.html, and injection is well made at startup.

However, when I call my resource, a new instance of the resource is created, according to JAX-RS spec. Spring is not used to create this new resource, so my dependencies are not injected.

The wink documentation page above states it's possible to change lifecycle of resources (so my injection would be made correctly), but there's no example for this.

I tried to play around with the @Scope annotation, but it didn't change anything... Anyone got a clue ? Thanks!


Solution

  • You should register your bean using the org.apache.wink.spring.Registrar Make sure that it appears in the instances section, so it will be reference to a bean and scope declared in the spring context will be used.

    Also check this post, you may find it helpful.