Earthly Powers
- All
- Fast Infoset
- General
- Java
- REST
Integrating Jersey and Spring: Take 3
Just in case it got hidden in the message of the 0.8 release Jersey now supplies Spring support via the spring maven module that was contributed by Martin.
So, rather than copying some code from my blog, you can depend on this module and reference the Spring servlet:
com.sun.jersey.spi.spring.container.servlet.SpringServlet
in the web.xml. That is it. Martin describes this in more detail here. Note that after this was written some changes were made to the package names as Martin describes here.
I am quite happy with it as we managed to solve a knotty issue of referencing Spring beans in constructor/method parameters that Jersey is responsible for invoking, thus JAX-RS/Jersey-based annotated parameters can be intermixed with Spring-based annotated or referenced parameters. Having said that i think we may be able to make the integration even smoother in two areas when using Spring-based annotation configuration: 1) inferring the life-cycle Jersey requires; and 2) reusing @Autowired for constructor/method parameters.
The mechanisms by which Jersey integrates with Spring can equally apply to Guice or WebBeans or a more specialized integration.
Posted at 08:48AM Aug 18, 2008 by Paul Sandoz in REST | Comments[1]
Just to drop a note here: As I posted in my blog ([1]) and on the mailing-list ([2]) there's now a new jersey sample "spring-annotations" ([3]) that shows how to use jersey and spring using annotations provided/supported by spring >= 2.5 (@Resource and @Autowired).
[1] http://www.javakaffee.de/blog/2008/08/31/added-new-jersey-sample-spring-annotations-how-to-use-jersey-and-springannotations/
[2] http://n2.nabble.com/Added-new-jersey-sample-spring-annotations-td795596.html
[3] https://jersey.dev.java.net/source/browse/jersey/trunk/jersey/samples/spring-annotations
Posted by Martin Grotzke on August 31, 2008 at 05:30 PM CEST #