Ahhh....I see now. I missed that call to createResource() in createResource(Request, Response).
Thanks! -Michael -----Original Message----- From: Jonathan Hall [mailto:[EMAIL PROTECTED] Sent: 26 February 2007 18:45 To: [email protected] Subject: Re: Spring context and Resource Here is how I am currently implementing it. It's pretty much a slight modification of the other wiki examples. It's just a quick example, it won't compile. (link due to no attachments) http://www.crysop.co.uk/restlet-spring.zip Hope it helps, Jonathan > in your Resource file: > > @Override > public void init(Context context, Request request, Response > response) { > super.init(context, request, response); > ... > } > > If you mean in the Finder: > > @Override > public Resource createResource(Request request, Response response) { > Resource result = createResource(); > > if (result != null) { > result.init(getContext(), request, response); > } > > return result; > } > > The new org.restlet.ext.spring.SpringFinder class has this all setup > for you. > > Jonathan > > Makunas, Michael wrote: >> Hi- >> >> Been lurking for a while but this is my first post so forgive my >> newbieness.... >> >> With solution 2, how do you call the init() method on the resource in >> such a way that it is aware of the restlet context? >> >> Cheers, >> Michael >> >> -----Original Message----- >> From: Jerome Louvel [mailto:[EMAIL PROTECTED] Sent: 26 February >> 2007 09:28 >> To: [email protected] >> Subject: RE: Spring context and Resource >> >> >> Hi all, >> >> Thanks for the discussion. I've added a SpringFinder class into the >> Spring >> extension package with the >> Javadocs based on solution 2. >> >> Best regards, >> Jerome >> >>> -----Message d'origine----- >>> De : Jonathan Hall [mailto:[EMAIL PROTECTED] Envoyé : samedi 24 >>> février 2007 16:10 >>> À : [email protected] >>> Objet : Re: Spring context and Resource >>> >>> Thankyou Valdis, I went with option 2 which works great. >>> >>> Jonathan >>> >>> >>> Valdis Rigdon 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 >>>>> >>>>> >>>>> >> >> > >

