Daniel Fagerstrom wrote:
> Carsten Ziegeler skrev:
>> Sylvain Wallez wrote:
>>
>>> However, a few remarks:
>>> - how is Processor different from Servlet?
>>>
>> The interface is similar. The difference is configuration and who
>> manages the component. If a processor is a component we can use all nice
>> features of spring for that and I think the configuration is nicer.
>> Things like changing the configuration at runtime should be easier as
>> well as you don't have to modify the web.xml.
>>
> Servlet is just an interface, no one prevents you from managing a
> component that implements Servlet in Spring. And as you rather often
> is going to need a Servlet context or configuration within a
> Processor, you end up pretty close to Servlet anyway.
>
> The advantage to use the Servlet interface is that we give the users
> greater flexibility in reusing the various controllers that we might
> implement.
Just for the record, here's the Servlet.init() method I use to have
Spring dependency injection in servlets declared in web.xml. Works like
a charm!
public void init(ServletConfig servletConfig) throws ServletException {
super.init(servletConfig);
// Get the application context,
ApplicationContext ctx = (ApplicationContext)
getServletContext().getAttribute(
WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
// Create an autowire-capable factory
DefaultListableBeanFactory factory = new
DefaultListableBeanFactory(ctx);
factory.autowireBeanProperties(this,
AutowireCapableBeanFactory.AUTOWIRE_BY_NAME, true);
}
Sylvain
--
Sylvain Wallez - http://bluxte.net