users@jersey.java.net

[Jersey] Spring integration improvement (_at_Component specializations support)

From: Konrad Garus <konrad.garus_at_gmail.com>
Date: Mon, 5 May 2014 11:01:30 +0200

Hello,

there are two similar issues in JIRA: JERSEY-2495 and JERSEY-2059. I've
also spent a few hours myself trying to figure this out.

The jersey-spring module has different behavior for Spring beans annotated
directly with @Component and other annotations. For example, Spring has
@Service, @Repository and @Controller annotations that are themselves
annotated with @Component, and are commonly used to better communicate the
bean role. In context of REST @Service and @Repository make perfect sense,
arguably more so than @Component.

Now, the SpringComponentProvider only supports beans annotated directly
with @Component. If a bean from Spring app context has this annotation, it
will be used directly for Jersey. Otherwise Jersey will create new
request-scoped instance for every request. Such instance does not have
complete Spring augmentation, for example it does not seem to have AOP
wrappers.

I propose to fix this by replacing this line in SpringComponentProvider:

if(component.isAnnotationPresent(Component.class)) {

... with a recursive check on all annotations. Get all annotations, and for
each of them *and their annotations* see if we can find @Component.

I can contribute a pull request for it (need to sign OCA first, but I'm OK
with it). Would such contribution be welcome?

-- 
Konrad Garus