类 SimpleServletPostProcessor
- java.lang.Object
- org.springframework.web.servlet.handler.SimpleServletPostProcessor
- 所有已实现的接口:
Aware,BeanPostProcessor,DestructionAwareBeanPostProcessor,ServletConfigAware,ServletContextAware
public class SimpleServletPostProcessor extends Object implements DestructionAwareBeanPostProcessor, ServletContextAware, ServletConfigAware
BeanPostProcessorthat applies initialization and destruction callbacks to beans that implement theServletinterface.After initialization of the bean instance, the Servlet
initmethod 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
destroywill 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
HttpServletBeanbase 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.- 从以下版本开始:
- 1.1.5
- 作者:
- Juergen Hoeller
- 另请参阅:
Servlet.init(javax.servlet.ServletConfig),Servlet.destroy(),SimpleServletHandlerAdapter
构造器概要
构造器 构造器 说明 SimpleServletPostProcessor()
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 ObjectpostProcessAfterInitialization(Object bean, String beanName)Apply thisBeanPostProcessorto the given new bean instance after any bean initialization callbacks (like InitializingBean'safterPropertiesSetor a custom init-method).voidpostProcessBeforeDestruction(Object bean, String beanName)Apply this BeanPostProcessor to the given bean instance before its destruction, e.g. invoking custom destruction callbacks.ObjectpostProcessBeforeInitialization(Object bean, String beanName)Apply thisBeanPostProcessorto the given new bean instance before any bean initialization callbacks (like InitializingBean'safterPropertiesSetor a custom init-method).booleanrequiresDestruction(Object bean)Determine whether the given bean instance requires destruction by this post-processor.voidsetServletConfig(ServletConfig servletConfig)Set theServletConfigthat this object runs in.voidsetServletContext(ServletContext servletContext)Set theServletContextthat this object runs in.voidsetUseSharedServletConfig(boolean useSharedServletConfig)Set whether to use the shared ServletConfig object passed in throughsetServletConfig, if available.
构造器详细资料
SimpleServletPostProcessor
public SimpleServletPostProcessor()
方法详细资料
setUseSharedServletConfig
public void setUseSharedServletConfig(boolean useSharedServletConfig)
Set whether to use the shared ServletConfig object passed in throughsetServletConfig, 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.
setServletContext
public void setServletContext(ServletContext servletContext)
从接口复制的说明:ServletContextAwareSet theServletContextthat this object runs in.Invoked after population of normal bean properties but before an init callback like InitializingBean's
afterPropertiesSetor a custom init-method. Invoked after ApplicationContextAware'ssetApplicationContext.- 指定者:
setServletContext在接口中ServletContextAware- 参数:
servletContext- the ServletContext object to be used by this object- 另请参阅:
InitializingBean.afterPropertiesSet(),ApplicationContextAware.setApplicationContext(org.springframework.context.ApplicationContext)
setServletConfig
public void setServletConfig(ServletConfig servletConfig)
从接口复制的说明:ServletConfigAwareSet theServletConfigthat this object runs in.Invoked after population of normal bean properties but before an init callback like InitializingBean's
afterPropertiesSetor a custom init-method. Invoked after ApplicationContextAware'ssetApplicationContext.- 指定者:
setServletConfig在接口中ServletConfigAware- 参数:
servletConfig- theServletConfigto be used by this object- 另请参阅:
InitializingBean.afterPropertiesSet(),ApplicationContextAware.setApplicationContext(org.springframework.context.ApplicationContext)
postProcessBeforeInitialization
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException
从接口复制的说明:BeanPostProcessorApply thisBeanPostProcessorto the given new bean instance before any bean initialization callbacks (like InitializingBean'safterPropertiesSetor a custom init-method). The bean will already be populated with property values. The returned bean instance may be a wrapper around the original.The default implementation returns the given
beanas-is.- 指定者:
postProcessBeforeInitialization在接口中BeanPostProcessor- 参数:
bean- the new bean instancebeanName- the name of the bean- 返回:
- the bean instance to use, either the original or a wrapped one; if
null, no subsequent BeanPostProcessors will be invoked - 抛出:
BeansException- in case of errors- 另请参阅:
InitializingBean.afterPropertiesSet()
postProcessAfterInitialization
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException
从接口复制的说明:BeanPostProcessorApply thisBeanPostProcessorto the given new bean instance after any bean initialization callbacks (like InitializingBean'safterPropertiesSetor a custom init-method). The bean will already be populated with property values. The returned bean instance may be a wrapper around the original.In case of a FactoryBean, this callback will be invoked for both the FactoryBean instance and the objects created by the FactoryBean (as of Spring 2.0). The post-processor can decide whether to apply to either the FactoryBean or created objects or both through corresponding
bean instanceof FactoryBeanchecks.This callback will also be invoked after a short-circuiting triggered by a
InstantiationAwareBeanPostProcessor.postProcessBeforeInstantiation(java.lang.Class<?>, java.lang.String)method, in contrast to all otherBeanPostProcessorcallbacks.The default implementation returns the given
beanas-is.- 指定者:
postProcessAfterInitialization在接口中BeanPostProcessor- 参数:
bean- the new bean instancebeanName- the name of the bean- 返回:
- the bean instance to use, either the original or a wrapped one; if
null, no subsequent BeanPostProcessors will be invoked - 抛出:
BeansException- in case of errors- 另请参阅:
InitializingBean.afterPropertiesSet(),FactoryBean
postProcessBeforeDestruction
public void postProcessBeforeDestruction(Object bean, String beanName) throws BeansException
从接口复制的说明:DestructionAwareBeanPostProcessorApply this BeanPostProcessor to the given bean instance before its destruction, e.g. invoking custom destruction callbacks.Like DisposableBean's
destroyand a custom destroy method, this callback will only apply to beans which the container fully manages the lifecycle for. This is usually the case for singletons and scoped beans.- 指定者:
postProcessBeforeDestruction在接口中DestructionAwareBeanPostProcessor- 参数:
bean- the bean instance to be destroyedbeanName- the name of the bean- 抛出:
BeansException- in case of errors- 另请参阅:
DisposableBean.destroy(),AbstractBeanDefinition.setDestroyMethodName(String)
requiresDestruction
public boolean requiresDestruction(Object bean)
从接口复制的说明:DestructionAwareBeanPostProcessorDetermine whether the given bean instance requires destruction by this post-processor.The default implementation returns
true. If a pre-5 implementation ofDestructionAwareBeanPostProcessordoes not provide a concrete implementation of this method, Spring silently assumestrueas well.- 指定者:
requiresDestruction在接口中DestructionAwareBeanPostProcessor- 参数:
bean- the bean instance to check- 返回:
trueifDestructionAwareBeanPostProcessor.postProcessBeforeDestruction(java.lang.Object, java.lang.String)is supposed to be called for this bean instance eventually, orfalseif not needed