org.springframework.web.servlet.handler
Class SimpleServletPostProcessor

java.lang.Object
  extended by org.springframework.web.servlet.handler.SimpleServletPostProcessor
All Implemented Interfaces:
BeanPostProcessor, DestructionAwareBeanPostProcessor, ServletContextAware

public class SimpleServletPostProcessor
extends Object
implements DestructionAwareBeanPostProcessor, ServletContextAware

Bean post-processor that applies initialization and destruction callbacks to beans that implement the Servlet interface.

After initialization of the bean instance, the Servlet init method will be called with a ServletConfig that contains the bean name of the Servlet and the ServletContext that it is running in.

Before destruction of the bean instance, the Servlet destroy will be called.

Note that this post-processor does not support Servlet initialization parameters. Bean instances that implement the Servlet interface are supposed to be configured like any other Spring bean, that is, through constructor arguments or bean properties.

For reuse of a Servlet implementation in a plain Servlet container and as a bean in a Spring context, consider deriving from Spring's HttpServletBean base class that applies Servlet initialization parameters as bean properties, supporting both initialization styles.

Alternatively, consider wrapping a Servlet with Spring's ServletWrappingController. This is particularly appropriate for existing Servlet classes, allowing to specify Servlet initialization parameters etc.

Since:
1.1.5
Author:
Juergen Hoeller
See Also:
Servlet, ServletConfig, SimpleServletHandlerAdapter, HttpServletBean, ServletWrappingController

Constructor Summary
SimpleServletPostProcessor()
           
 
Method Summary
 Object postProcessAfterInitialization(Object bean, String beanName)
          Apply this BeanPostProcessor to the given new bean instance after any bean initialization callbacks (like InitializingBean's afterPropertiesSet or a custom init-method).
 void postProcessBeforeDestruction(Object bean, String beanName)
          Apply this BeanPostProcessor to the given bean instance before its destruction.
 Object postProcessBeforeInitialization(Object bean, String beanName)
          Apply this BeanPostProcessor to the given new bean instance before any bean initialization callbacks (like InitializingBean's afterPropertiesSet or a custom init-method).
 void setServletContext(ServletContext servletContext)
          Set the ServletContext that this object runs in.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleServletPostProcessor

public SimpleServletPostProcessor()
Method Detail

setServletContext

public void setServletContext(ServletContext servletContext)
Description copied from interface: ServletContextAware
Set the ServletContext that this object runs in.

Invoked after population of normal bean properties but before an init callback like InitializingBean's afterPropertiesSet or a custom init-method. Invoked after ApplicationContextAware's setApplicationContext.

Specified by:
setServletContext in interface ServletContextAware
Parameters:
servletContext - ServletContext object to be used by this object

postProcessBeforeInitialization

public Object postProcessBeforeInitialization(Object bean,
                                              String beanName)
                                       throws BeansException
Description copied from interface: BeanPostProcessor
Apply this BeanPostProcessor to the given new bean instance before any bean initialization callbacks (like InitializingBean's afterPropertiesSet or a custom init-method). The bean will already be populated with property values. The returned bean instance may be a wrapper around the original.

Specified by:
postProcessBeforeInitialization in interface BeanPostProcessor
Parameters:
bean - the new bean instance
beanName - the name of the bean
Returns:
the bean instance to use, either the original or a wrapped one
Throws:
BeansException - in case of errors
See Also:
InitializingBean.afterPropertiesSet()

postProcessAfterInitialization

public Object postProcessAfterInitialization(Object bean,
                                             String beanName)
                                      throws BeansException
Description copied from interface: BeanPostProcessor
Apply this BeanPostProcessor to the given new bean instance after any bean initialization callbacks (like InitializingBean's afterPropertiesSet or a custom init-method). The bean will already be populated with property values. The returned bean instance may be a wrapper around the original.

Specified by:
postProcessAfterInitialization in interface BeanPostProcessor
Parameters:
bean - the new bean instance
beanName - the name of the bean
Returns:
the bean instance to use, either the original or a wrapped one
Throws:
BeansException - in case of errors
See Also:
InitializingBean.afterPropertiesSet()

postProcessBeforeDestruction

public void postProcessBeforeDestruction(Object bean,
                                         String beanName)
                                  throws BeansException
Description copied from interface: DestructionAwareBeanPostProcessor
Apply this BeanPostProcessor to the given bean instance before its destruction. Can invoke custom destruction callbacks.

Like DisposableBean's destroy and a custom destroy method, this callback just applies to singleton beans in the factory (including inner beans).

Specified by:
postProcessBeforeDestruction in interface DestructionAwareBeanPostProcessor
Parameters:
bean - the bean instance to be destroyed
beanName - the name of the bean
Throws:
BeansException - in case of errors
See Also:
DisposableBean, AbstractBeanDefinition.setDestroyMethodName(java.lang.String)


Copyright (c) 2002-2007 The Spring Framework Project.