On Sun, 2008-08-03 at 01:34 -0600, Arjun Robinson wrote:
> Hi,
>  
> Can some one point me to how I can integrate Spring with Restlet's JSR
> 311 extensions? I could not use the default SpringServerServlet and
> would like to know how I can make spring factory the Resource classes?
> Any code snippets of the same would be appreciated.

You can take over the instantiation of the resource classes by setting
an ObjectFactory on the JaxRsApplication or JaxRsRestlet.

Here's some example code, it makes the assumption you have a Spring
ApplicationContext and a JaxRsRestlet.

AutowireCapableBeanFactory beanFactory =
applicationContext.getAutowireCapableBeanFactory();

ObjectFactory objectFactory = new ObjectFactory() {
    public <T> T getInstance(Class<T> clazz) throws InstantiateException {
        return (T)beanFactory.createBean(clazz, 
AutowireCapableBeanFactory.AUTOWIRE_AUTODETECT, false);
    }
};

jaxRsRestlet.setObjectFactory(objectFactory);

-- 
Bruno Dumon                             http://outerthought.org/
Outerthought                            http://www.daisycms.org/
[EMAIL PROTECTED]              http://www.kauriproject.org/

Reply via email to