This issue has been discussed on the Jersey users mailing list during 2013 may-july.
The following functional requirements were specified for Jersey Spring integration:
- inject Spring beans into jersey JAX-RS resource classes and providers (filters, interceptors, ...)
- injection by @Autowire
- injection by @Inject
- allow JAX-RS resource classes and providers to be managed by Spring instead of Jersey
- inject Jersey injections into the Spring managed JAX-RS resource classes and providers (these mentioned in point 2)
- inject by @Inject and @Context (this is needed as resource classes must still be compliant with JAX-RS spec which allows injection of JAX-RS providers be these annotations). This means Spring managed beans will support these injections.
- and of course allow standard Spring injection for these Spring managed beans with @Autowire, definition by xml (applicationContext.xml), @Inject
The prototype should satisfy these requirements.
These features have been implemented and demonstrated in examples HelloWorldResource1 through HelloWorldResource3.
About scopes: Spring manages bean lifecycle for Spring managed beans.
Jersey scopes map to Spring scopes in the following manner:
- @RequestScope ==> scope="request" or @Scope("request")
- @Singleton ==> scope="singleton" or @Scope("singleton")
- @PerLookup ==> scope="prototype" @Scope("prototype")
Here's how to build the prototype and examples:
# building the Jersey Spring integration
git clone https:cd jersey/ext/jersey-spring
mvn clean install
# building the Jersey Spring integration example web app
mvn clean install
NOTE: configure log level for org.glassfish.jersey.server.spring category to ALL in your application server to see log messages about Jersey Spring integration.
(Scope functionality can be validated e.g. by enabling debug logging as described above and tracing object identity in the log)
Feedback is welcome!