Hi Dan,
Firstly: thanks for the feedback.
Please see inline for responses...
On Aug 19, 2013, at 9:10 PM, Daniel Kirkdorffer <dankirkd_at_comcast.net> wrote:
> I'm seeing some oddities with the Spring Integration added with Jersey 2.2.
>
> But firstly a question: does Jersey 2.2 only support Spring Dependency Injection with annotations? I can't get things to work at all with XML configurations.
The helloworld-spring-webapp example (see [1]) utilises XML configuration. The config file is registered via the web.xml descriptor there.
So XML configuration should be doable. If it is not the case, could you please provide some details on what does not work for you?
>
> But on to my observations with the Spring Integration (using annotations).
>
> I would have expected that if I annotated my service with @Service I would get a singleton on each web service call via Jersey. But instead I see a new instance of my service is instantiated every time, albeit injected with the same instance of the one DAO I'm injecting into it. The same behavior is true if I user @Controller, or @Repository. However, if I use @Component the same instance of my service is returned each time.
This is definitely a bug. Jersey Spring integration indeed only honours the @Component annotation.
Could you please file a new Jersey JIRA bug report for this?
>
> I would have expected that all four of these annotations would have yielded the same results.
>
> The other thing I find weird is that @Singleton behaves differently when used with these annotations. If I use @Singleton with @Service, @Controller, or @Repository, my constructor and setters are not called again after the first web service call. However, with @Component the setters are.
>
> Finally, I was under the impression that @Scope("singleton") and @Singleton did the same thing (and of course that @Scope("singleton") was the same as not having the scope defined as "singleton" is the default). Well it seems not: if I use @Scope("singleton") instead of @Singleton, then for @Service, @Controller, or @Repository my constructor and setters are called, and I DON'T get the same instance of my service back each call, I get a different one. With @Component, the setters are called and I DO get the same instance of my service back each time.
I am not sure, but this would probably be resolved with the above mentioned issue (complying also with the other Spring annotations beside @Component).
Just to make sure this gets covered, could you please file another JIRA issue for this one?
>
> So I've settled on using @Service @Singleton, but I'm scratching my head about why I'm seeing all this different behaviour.
I am glad you figured out a workaround. We will try to fix things in Jersey 2.3, so that you do not need to rely on it in the next version.
Thanks,
~Jakub
[1]
https://github.com/jersey/jersey/tree/master/examples/helloworld-spring-webapp
>
> Dan
>
> ---
> Daniel Kirkdorffer
> dankirkd_at_comcast.net
>
>