users@jersey.java.net

[Jersey] Re: Spring framework support for Jersey 2

From: Marko Asplund <marko.asplund_at_gmail.com>
Date: Sat, 6 Jul 2013 22:31:00 +0300

Hi Mira,

Thanks for your reply.

I reviewed the Spring integration requirement you listed and found some
gaps with in the prototype.
The gaps were fixed and the prototype should now satisfy the requirements.

If someone wants to build the prototype and examples, here's how to do it:

# building the Jersey Spring integration
git clone https://github.com/marko-asplund/jersey
cd jersey/ext/jersey-spring
mvn clean install

# building the Jersey Spring integration example web app
cd ../../examples/helloworld-spring
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.

Feedback is welcome!

AFAIK, all the currently existing extension points in Jersey 2 (and HK2)
are sufficient for implementing Spring integration.
Have you identified any specific areas where modifications would be
required in Jersey?

What kinds of changes are expected in Jersey 2 / HK2 wrt. Spring
integration?
Are you referring to the HK2 "spring-bridge"?
What's the timeframe for releasing an updated HK2?
Are changes required in Jersey as well? What's the schedule for the Jersey
changes?
I think a lot of people are interested in Jersey Spring integration and
would like to see a working version released soon.

More responses to more specific comments below:

(ps. I've signed the OCA and sent it to Oracle a few days ago).


On 4 July 2013 18:45, Miroslav Fuksa <miroslav.fuksa_at_oracle.com> wrote:

> ...
>
> This is summary of requirements from injection perspective:
>
> 1. inject Spring beans into jersey JAX-RS resource classes and providers
> (filters, interceptors, ...)
> - injection by @Autowire
> - injection by @Inject
>

implemented and demonstrated in HelloWorldResource1 example.


> 2. allow JAX-RS resource classes and providers to be managed by Spring
> instead of Jersey
>

implemented and demonstrated in HelloWorldResource2 and HelloWorldResource3
examples


> 3. 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.
>

implemented and demonstrated in HelloWorldResource2 example


> - and of course allow standard Spring injection for these Spring
> managed beans with @Autowire, definition by xml (applicationContext.xml),
> @Inject
>

implemented and demonstrated in HelloWorldResource2 and HelloWorldResource3
examples


> We will also need to migrate Jersey 1 samples as you have written.
>
> I have some more comments below....
>
> Thanks
> Mira
>
>
> On 06/29/2013 11:47 PM, Marko Asplund wrote:
> ...
>
> - support singleton and request scopes for both of the above
>
> yes, the scopes should be supported. This means when you annotate the
> resource or provider with @RequestScope, @Singleton or @PerLookup, the
> scoping should work correctly for spring managed resources and providers as
> it currently works for jersey managed ones. I am now not exactly sure how
> to managed spring definition of scopes but probably this should be still
> managed by spring in the spring way but might be overriden by Jersey scope
> annotations. But I am not sure about this point.
>
>
Yes, 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")

This is implemented and currently demonstrated in examples
HelloWorldResource1 through HelloWorldResource3 for request and singleton
scopes, but should work also for PerLookup scope.
(Scope functionality can be validated e.g. by enabling debug logging as
described above and tracing object identity in the log)


best regards,

marko