org.springframework.beans.factory.config.BeanPostProcessor
that applies initialization and destruction callbacks to beans that
implement the jakarta.servlet.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
org. 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
org..
This is particularly appropriate for existing Servlet classes,
allowing to specify Servlet initialization parameters etc.
jakarta.servlet.Servlet#init(jakarta.servlet.ServletConfig) , jakarta.servlet.Servlet#destroy() , SimpleServletHandlerAdapter
| Modifier and Type | Class and Description |
|---|---|
| private static class | SimpleServletPostProcessor.
Internal implementation of the |
| Modifier and Type | Field and Description |
|---|---|
| private ServletConfig | |
| private ServletContext | |
| private boolean |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public Object | postProcessAfterInitialization(Object
the new bean instance bean, String the name of the bean beanName)Overrides default org. Apply this |
| public void | postProcessBeforeDestruction(Object
the bean instance to be destroyed bean, String the name of the bean beanName)Implements org. Apply this BeanPostProcessor to the given bean instance before its destruction, e.g. invoking custom destruction callbacks. |
| public Object | postProcessBeforeInitialization(Object
the new bean instance bean, String the name of the bean beanName)Overrides default org. Apply this |
| public boolean | requiresDestruction(Object
the bean instance to check bean)Overrides default org. Determine whether the given bean instance requires destruction by this post-processor. |
| public void | setServletConfig(ServletConfig
the servletConfig)ServletConfig to be used by this objectImplements org. Set the Invoked after population of normal bean properties but before an init
callback like InitializingBean's |
| public void | setServletContext(ServletContext
the ServletContext object to be used by this object servletContext)Implements org. Set the Invoked after population of normal bean properties but before an init
callback like InitializingBean's |
| public void | setUseSharedServletConfig(boolean useSharedServletConfig)
Set whether to use the shared ServletConfig object passed in
through |
| servletConfig | back to summary |
|---|---|
| private ServletConfig servletConfig
| |
| servletContext | back to summary |
|---|---|
| private ServletContext servletContext
| |
| useSharedServletConfig | back to summary |
|---|---|
| private boolean useSharedServletConfig | |
| SimpleServletPostProcessor | back to summary |
|---|---|
| public SimpleServletPostProcessor() | |
| postProcessAfterInitialization | back to summary |
|---|---|
| public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException Overrides default org. Doc from org. Apply this 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 This callback will also be invoked after a short-circuiting triggered by a
The default implementation returns the given
| |
| postProcessBeforeDestruction | back to summary |
|---|---|
| public void postProcessBeforeDestruction(Object bean, String beanName) throws BeansException Implements org. Apply this BeanPostProcessor to the given bean instance before its destruction, e.g. invoking custom destruction callbacks. Like DisposableBean's
| |
| postProcessBeforeInitialization | back to summary |
|---|---|
| public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException Overrides default org. Doc from org. Apply this The default implementation returns the given
| |
| requiresDestruction | back to summary |
|---|---|
| public boolean requiresDestruction(Object bean) Overrides default org. Doc from org. Determine whether the given bean instance requires destruction by this post-processor. The default implementation returns
| |
| setServletConfig | back to summary |
|---|---|
| public void setServletConfig(ServletConfig servletConfig) Implements org. Doc from org. Set the Invoked after population of normal bean properties but before an init
callback like InitializingBean's
| |
| setServletContext | back to summary |
|---|---|
| public void setServletContext(ServletContext servletContext) Implements org. Doc from org. Set the Invoked after population of normal bean properties but before an init
callback like InitializingBean's
| |
| setUseSharedServletConfig | back to summary |
|---|---|
| public void setUseSharedServletConfig(boolean useSharedServletConfig) Set whether to use the shared ServletConfig object passed in
through 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.
| |
ServletConfig interface,
to be passed to the wrapped servlet.
| Modifier and Type | Field and Description |
|---|---|
| private final ServletContext | |
| private final String |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public String | getInitParameter(String
a paramName)String specifying the name of the initialization parameterImplements jakarta. Returns a |
| public Enumeration | getInitParameterNames()
Implements jakarta. Returns the names of the servlet's initialization parameters as an |
| public ServletContext | getServletContext()
Implements jakarta. Returns a reference to the |
| public String | getServletName()
Implements jakarta. Returns the name of this servlet instance. |
| servletContext | back to summary |
|---|---|
| private final ServletContext servletContext
| |
| servletName | back to summary |
|---|---|
| private final String servletName | |
| DelegatingServletConfig | back to summary |
|---|---|
| public DelegatingServletConfig(String servletName, ServletContext servletContext) | |
| getInitParameter | back to summary |
|---|---|
| public String getInitParameter(String paramName) Implements jakarta. Doc from jakarta. Returns a | |
| getInitParameterNames | back to summary |
|---|---|
| public Enumeration Implements jakarta. Doc from jakarta. Returns the names of the servlet's initialization parameters as an
| |
| getServletContext | back to summary |
|---|---|
| public ServletContext getServletContext() Implements jakarta. Doc from jakarta. Returns a reference to the
| |
| getServletName | back to summary |
|---|---|
| public String getServletName() Implements jakarta. Doc from jakarta. Returns the name of this servlet instance. The name may be provided via server administration, assigned in the web application deployment descriptor, or for an unregistered (and thus unnamed) servlet instance it will be the servlet's class name. | |