On 2 August 2010 10:36, Paul Sandoz <Paul.Sandoz_at_oracle.com> wrote:
> Hi James,
>
> You are correct, nothing is mentioned in the spec, although i expected it
> should.
>
> IIRC the reason why we did not perform injection on non-null field values is
> because they could have been set by the constructor or at initialization,
> and the time we considered it better not to overwrite something that was
> already set by the developer.
>
> I did a quick test with Guice and it overwrites fields.
Spring does the same too if you annotate the field. Its no different
really from having default fields and then doing property injection in
spring to override a property value (after the constructor has been
called).
> So perhaps we could
> relax this constraint and the developer should take care mixing injection
> declarations that could results in IoC frameworks fighting over an injection
> target?
Agreed.
Each annotation should only be injected by one IoC framework (i.e. an
annotation is a JAXRS annotation or a Guice or Spring one etc); for
injection points which are optional (e.g. a @QueryParam may be
specified in a request or it might be absent) - then the field/method
injection may occur or not. This is similar to having a bean in Spring
where the bean might have a property injected or not (based on the IoC
configuration).
When an injection point is optional its useful to be able to provide a
default value in case the injection does not occur - but its totally
fine for the injection to override the value.
I've raised an issue for this:
https://jersey.dev.java.net/issues/show_bug.cgi?id=564
--
James
-------
http://macstrac.blogspot.com/
Open Source Integration
http://fusesource.com/