users@jersey.java.net

Re: Injecting spring beans annotation based

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Tue, 25 Mar 2008 13:22:32 +0100

On Mar 24, 2008, at 5:07 PM, Martin Grotzke wrote:

> Hi Paul,
>
> On Tue, 2008-03-18 at 11:26 +0100, Paul Sandoz wrote:
>> Hi Martin,
>>
>> In relation to this you might want to check out a blog comment
>> from James:
>>
>> http://blogs.sun.com/sandoz/entry/
>> integrating_jersey_and_spring_take#comment-1205397278000
>>
>> it is using the Spring auto-wiring feature (if a bean is not
>> registered
>> in the XML config). Perhaps this may do what you require without
>> having
>> to create your own annotation?
> now I tried James' solution using autowiring. Besides that I
> personally
> don't like autowiring very much but prefer more explicit approaches, I
> find it hard to decide if it might be critical/dangerous that also all
> jersey components are created as spring beans. E.g. what happens if
> these are created as proxies for some reason...
>

You mean a "man-in-the-middle" kind of attack? is it not up to the
application developer/deployer to ensure things are configured
correctly and securely?


> Therefore I'd suggest to provide autowiring of resource classes via an
> @Autowire annotation (so that only these classes are created as spring
> beans, but not jersey components). Additionally one could configure
> its
> bean directly in the applicationContext, or even use some
> @SpringBean/_at_Inject annotation for explicit wiring of resource classes
> without beeing forced to defined them all in
> applicationContext.xml. The
> latter one would also be useful for parameter injection, that I would
> really like to have available for IoC-container managed beans.
>

I sort of anticipated (perhaps incorrectly) that this functionality
would be more an application wide-setting i.e. you either want this
for all components (user defined and Jersey defined) or not at all.


> One question that I have: what is the implementation of inject(Object)
> good for, which scenario shall be supported by this?
>

I anticipated that if the underlying ComponentProvider could not
instantiate a class (e.g. per-request with a Jersey specific
constructor) then Jersey could instantiate and then call
ComponentProvider.inject. That was the intention, but i realized i
forgot to put that in the Jersey code.

Paul.