public class SimpleServletPostProcessor extends 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.
Servlet.init(javax.servlet.ServletConfig)
,
Servlet.destroy()
,
SimpleServletHandlerAdapter
Constructor and Description |
---|
SimpleServletPostProcessor() |
Modifier and Type | Method and Description |
---|---|
Object |
postProcessAfterInitialization(Object bean,
String beanName) |
void |
postProcessBeforeDestruction(Object bean,
String beanName) |
Object |
postProcessBeforeInitialization(Object bean,
String beanName) |
boolean |
requiresDestruction(Object bean) |
void |
setServletConfig(ServletConfig servletConfig) |
void |
setServletContext(ServletContext servletContext) |
void |
setUseSharedServletConfig(boolean useSharedServletConfig)
Set whether to use the shared ServletConfig object passed in
through
setServletConfig , if available. |
public void setUseSharedServletConfig(boolean useSharedServletConfig)
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.
public void setServletContext(ServletContext servletContext)
setServletContext
in interface org.springframework.web.context.ServletContextAware
public void setServletConfig(ServletConfig servletConfig)
setServletConfig
in interface org.springframework.web.context.ServletConfigAware
public Object postProcessBeforeInitialization(Object bean, String beanName) throws org.springframework.beans.BeansException
postProcessBeforeInitialization
in interface org.springframework.beans.factory.config.BeanPostProcessor
org.springframework.beans.BeansException
public Object postProcessAfterInitialization(Object bean, String beanName) throws org.springframework.beans.BeansException
postProcessAfterInitialization
in interface org.springframework.beans.factory.config.BeanPostProcessor
org.springframework.beans.BeansException
public void postProcessBeforeDestruction(Object bean, String beanName) throws org.springframework.beans.BeansException
postProcessBeforeDestruction
in interface org.springframework.beans.factory.config.DestructionAwareBeanPostProcessor
org.springframework.beans.BeansException
public boolean requiresDestruction(Object bean)
requiresDestruction
in interface org.springframework.beans.factory.config.DestructionAwareBeanPostProcessor