users@jersey.java.net

Re: Injecting spring beans annotation based

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

On Mar 23, 2008, at 6:27 PM, Martin Grotzke wrote:

> On Wed, 2008-03-19 at 11:16 +0100, Paul Sandoz wrote:
>> Martin Grotzke wrote:
>>> Hi,
>>>
>>> On Mon, 2008-03-17 at 14:45 +0100, Paul Sandoz wrote:
>>>> Why can't the registered Spring beans be injected into other things
>>>> using Spring-based mechanisms? I know that Guice has the @Injected
>>>> annotation, does Spring have a similar annotation? you can
>>>> probably wire
>>>> things up in the app config but it is not as nice as an annotation.
>>> I think in spring 2.5 annotation-based DI has been improved
>>> significantly. Though, we're still using spring 2.0 and do not use
>>> spring annotations for wiring up beans, so I don't know what are
>>> all the
>>> possibilities provided (just having a look at the spring docs
>>> shows that
>>> e.g. the javax.annotation.Resource is supported).
>>>
>>
>> OK. I thought Spring provides (or was going to provide) support
>> for EE5.
> Which parts of EE5 do you have in mind?
>

All of it related to things you can do on EJBs :-) i.e. namely i
don't want to re-implement all the EE5 annotation support for
resource classes and other components.


> From the spring 2.5 announcement [1]:
> - Full Java 6 and Java EE 5 support (JDBC 4.0, JTA 1.1, JavaMail 1.4,
> JAX-WS 2.0)
>
> More details on e.g. annotation based configuration or support for the
> JSR-250 @Resource annotation can be found at [2] and [3], but I didn't
> have the time to play with it.
>
>
>> Spring or WebBeans (preferably WebBeans) will be the way we support
>> EE5/EE6 stuff for Jersey so we don't have to implement it ourselves.
> I'm not so comfortable with WebBeans, but after a very short look
> at the
> jsr details it looks really promising!
>

See my next email i will send after this :-)


>>>> The Injectable interface was really designed for "constant" Java
>>>> types
>>>> rather than application defined types (and minimal way of
>>>> performing
>>>> injection of a fixed set of common stuff without depending on an
>>>> IoC
>>>> container). So i think it best to see if there is Spring-way before
>>>> making changes around support of this interface.
>>> Alright. Though, it's really nice and easy and therefore was
>>> somehow an
>>> invitation to use / play with it ;)
>>>
>>
>> Great, it was a really nice surprise to see you doing that :-) i
>> am glad
>> it works for you.
>>
>> If we cannot find an alternative Spring way that is acceptable and
>> the
>> current approach starts to cause you pain we can look into
>> changing the
>> injectable behvaiour to support what you require.
> Hmm, still not sure what would be the best approach...
>

I would be inclined to go the IoC route if at all possible so as not
to re-/impl/invent too much IoC functionality.


>>
>> A question: Is Tapestry a bit like Wicket?
> There are similarities but also big differences. AFAIK wicket creates
> one component/page instance per request, whereas tapestry manages a
> pool
> of page instances. Page instances are proxied and enhanced by
> tapestry,
> and have a certain lifecycle. I'd say that a resource class probably
> would not be a page class, but one might imagine that you return some
> tapestry page from a resource method? Or specify a tapestry page as
> result view that gets activated with the return value of the resource
> method...
> Just to mention it: I know nothing about jersey MVC (besides that you
> can specify some @View that is probably using to forward to...?).
>

It has changed to be a little more flexible, there were some
discussions on the users list between myself and Jo Storse. Jo
protyped FreeMarker support and JAXB XSLT translations. Unless
implicitly specified one returns an instance of Viewable. It sounds
like as you say one would return a reference to a Tapestry page.

One thing i would really be interested in seeing is a resource class
that has 'snippets' functionality for producing bits of the page. The
view technology operates on the snippets functionality of the
resource class (this idea is taken from the lift web framework
written in Scala, the snippet functionality is really nice).

Paul.

> Cheers,
> Martin
>
>
>> Is it possible to merge
>> Tapestry and Jersey together is anyway? for example, i am thinking if
>> there is a connection to the basic-MVC stuff we put into Jersey,
>> or if a
>> resource class can also be a page?
>
>
>
> [1] http://www.springframework.org/node/561
> [2] http://static.springframework.org/spring/docs/2.5.x/reference/
> beans.html#beans-annotation-config
> [3] http://static.springframework.org/spring/docs/2.5.x/reference/
> beans.html#beans-resource-annotation
>
>>
>> Paul.
>>