spring-webmvc

org.springframework.web.servlet.handler
Class SimpleServletPostProcessor

java.lang.Object
  extended by org.springframework.web.servlet.handler.SimpleServletPostProcessor
All Implemented Interfaces:
org.springframework.beans.factory.Aware, org.springframework.beans.factory.config.BeanPostProcessor, org.springframework.beans.factory.config.DestructionAwareBeanPostProcessor, org.springframework.web.context.ServletConfigAware, org.springframework.web.context.ServletContextAware

public class SimpleServletPostProcessor
extends java.lang.Object
implements org.springframework.beans.factory.config.DestructionAwareBeanPostProcessor, org.springframework.web.context.ServletContextAware, org.springframework.web.context.ServletConfigAware

BeanPostProcessor 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 the standard Servlet and the Spring bean initialization style.

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.init(javax.servlet.ServletConfig), Servlet.destroy(), SimpleServletHandlerAdapter

Constructor Summary
SimpleServletPostProcessor()
           
 
Method Summary
 java.lang.Object postProcessAfterInitialization(java.lang.Object bean, java.lang.String beanName)
           
 void postProcessBeforeDestruction(java.lang.Object bean, java.lang.String beanName)
           
 java.lang.Object postProcessBeforeInitialization(java.lang.Object bean, java.lang.String beanName)
           
 void setServletConfig(javax.servlet.ServletConfig servletConfig)
           
 void setServletContext(javax.servlet.ServletContext servletContext)
           
 void setUseSharedServletConfig(boolean useSharedServletConfig)
          Set whether to use the shared ServletConfig object passed in through setServletConfig, if available.
 
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

setUseSharedServletConfig

public void setUseSharedServletConfig(boolean useSharedServletConfig)
Set whether to use the shared ServletConfig object passed in through setServletConfig, if available.

Default is "true". Turn this setting to "false" to pass in a mock ServletConfig object with the bean name as servlet name, holding the current ServletContext.

See Also:
setServletConfig(javax.servlet.ServletConfig)

setServletContext

public void setServletContext(javax.servlet.ServletContext servletContext)
Specified by:
setServletContext in interface org.springframework.web.context.ServletContextAware

setServletConfig

public void setServletConfig(javax.servlet.ServletConfig servletConfig)
Specified by:
setServletConfig in interface org.springframework.web.context.ServletConfigAware

postProcessBeforeInitialization

public java.lang.Object postProcessBeforeInitialization(java.lang.Object bean,
                                                        java.lang.String beanName)
                                                 throws org.springframework.beans.BeansException
Specified by:
postProcessBeforeInitialization in interface org.springframework.beans.factory.config.BeanPostProcessor
Throws:
org.springframework.beans.BeansException

postProcessAfterInitialization

public java.lang.Object postProcessAfterInitialization(java.lang.Object bean,
                                                       java.lang.String beanName)
                                                throws org.springframework.beans.BeansException
Specified by:
postProcessAfterInitialization in interface org.springframework.beans.factory.config.BeanPostProcessor
Throws:
org.springframework.beans.BeansException

postProcessBeforeDestruction

public void postProcessBeforeDestruction(java.lang.Object bean,
                                         java.lang.String beanName)
                                  throws org.springframework.beans.BeansException
Specified by:
postProcessBeforeDestruction in interface org.springframework.beans.factory.config.DestructionAwareBeanPostProcessor
Throws:
org.springframework.beans.BeansException

spring-webmvc