On Wed, 2008-08-27 at 14:52 +0200, Paul Sandoz wrote:
> Martin Grotzke wrote:
> >> We can supply an implementation of an InjectableProvider that reuses
> >> the Autowired annotation. That implementation can be equivalent to
> >> that of our own @Inject annotation. So for Spring 2.5.x users they do
> >> not require a Jersey specific annotation.
> > Hmm, I'm somehow confused. Spring 2.5 users already can use the Spring
> > annotations and don't have to use our @Inject. Spring does the whole job
> > based on the spring 2.5 annotations. Though, I don't want to depend on
> > the spring 2.5 annotations but still support spring 2.0.
> >
>
> On fields yes, but not for constructors and methods that Jersey is
> responsible for invoking. It would only require supporting on 2.5.x.
@Autowired is used by spring at bean creation time. So if you have a
spring bean that has annotated some method with @Autowired spring would
try to invoke this method when it creates the object. If there's any
method argument that spring cannot supply:
"By default, the autowiring will fail whenever zero candidate beans are
available; the default behavior is to treat annotated methods,
constructors, and fields as indicating required dependencies. This
behavior can be changed as demonstrated below." [1]
I'd prefer not to redefine the semantics of @Autowired in the context of
jersey, as this might force users to change their software when the
start using jersey.
Or do you have restrictions in mind, when jersey should use spring's
@Autowired annotation? Perhaps you might give an example how this should
be used?
>
>
> > You might have a look at AutowiredBySpringSingletonResource and
> > AnnotatedSingletonResource for the current usage of spring 2.5
> > annotations.
> >
> > And I'm aware we need some spring example, perhaps I find the time to
> > create one this week - if no one else comes first :)
> >
>
> Imran offered to work on one as well, perhaps you can work together?
Yes, I just answered him.
>
>
> >> I also think we may be able to support better life-cycle integration
> >> by enabling the SpringServlet to declare the life-cycle choosing
> >> factory mechanism. Thus when using @Component there may be no need to
> >> duplicate Jersey life-cycle declarations. I think this may be
> >> possible by declaring a default life-cycle when a Jersey life-cycle
> >> annotation is absent, looks at the spring annotations on the class,
> >> and defers to the appropriate Jersey life-cycle.
> > Probably my holiday was too long, again I'm not sure if I understand
> > you ;)
> >
> > Trying to express what I understood/read: You want that jersey(-spring)
> > reads the lifecycle from the spring annotations, if no jersey lifecycle
> > is declared but a resource class is annotated with @Component?
>
> Yes.
>
>
> > So the ComponentProvider would tell jersey of what scope a component is,
> > if the Scope is not defined by some jersey annotation?
> >
>
> I don't think there is a need for that. The property:
>
> "com.sun.jersey.config.property.DefaultResourceProviderClass"
>
> can be set to declare a default ResourceProvider when one is not
> declared on a resource class. Thus the SpringServlet can set this
> property (if not already set) and the SpringServlet ResourceProvider
> implementation can look at the @Component annotation and choose to defer
> to the singleton or per-request ResourceProvider implementations.
Ok. I'll do a basic implementation (depending on spring 2.5) and send
you a diff.
Cheers,
Martin
[1]
http://static.springframework.org/spring/docs/2.5.x/reference/beans.html#beans-autowired-annotation
>
> Paul.