Approach 2 sounds good, but is this injectable Finder something that can be
added into the stock Restlet distribution?  It wouldn't just be useful for
spring but also for other dependency injection frameworks...

R

On 2/23/07, Valdis Rigdon <[EMAIL PROTECTED]> wrote:

I've found 2 approaches that work, and there are possibly more.

1.  Use @Configurable on your Resource classes, and use Spring AOP to
inject dependencies.  Search the message archives for more details on
this.

2.  If you don't like having the dependency on AspectJ, you can extend
org.restlet.Finder and override createResource(Request, Response) to
delegate to a no-arg createResource() method (but be sure to call init()
on it after it's created).  Then create a singleton Spring bean based on
that Finder,  and configure it using "lookup-method" to return instances
of a "prototype" bean for createResource().  Finally, attach the Finder
to your Router.  When the createResource() method is invoked, a new
instance of your prototype bean will be created and returned.


A sample xml for "lookup-method":

<bean id="myRestlet" class="com.mycompany.rest.SpringFinder">
        <lookup-method name="createResource" bean="myResource"/>
</bean>
<bean id="myResource" class="com.mycompany.rest.resource.MyResource"
scope="prototype">
    <property name="aProperty" value="anotherOne"/>
    <property name="oneMore" value="true"/>
</bean>


Perhaps org.restlet.Finder could be reworked so this worked out of the
box, instead of having to have a custom Finder object.


Valdis


Jonathan Hall wrote:
> Hi,
>
> Following the wiki examples, I integrated Spring and Restlet by using an
> extended Restlet bean and handle(Request request, Response response).
> However, it seems I would want to extend Resource instead, as it has all
> the gubbins for get/post/put/etc. The problem is the router accepts a
> class and not an object; so I can't use Spring to inject other beans
> into my extended class.
>
> The following options occur to me:
> modify Router to accept instances,
> recreate the spring context on every call in the Resource,
> stash the springcontext in the restlet context.
>
> Have I missed something that would solve this problem, or misunderstood
> the framework? If not, then would it be possible to add something to
> help with this in future releases?
>
> Thanks for all the great work, I'm enjoying learning this framework.
>
> Best Regards,
> Jonathan
>
>

Reply via email to