类 GenericFilterBean
- java.lang.Object
- org.springframework.web.filter.GenericFilterBean
- 所有已实现的接口:
Filter
,Aware
,BeanNameAware
,DisposableBean
,InitializingBean
,EnvironmentAware
,EnvironmentCapable
,ServletContextAware
public abstract class GenericFilterBean extends Object implements Filter, BeanNameAware, EnvironmentAware, EnvironmentCapable, ServletContextAware, InitializingBean, DisposableBean
Simple base implementation ofFilter
which treats its config parameters (init-param
entries within thefilter
tag inweb.xml
) as bean properties.A handy superclass for any type of filter. Type conversion of config parameters is automatic, with the corresponding setter method getting invoked with the converted value. It is also possible for subclasses to specify required properties. Parameters without matching bean property setter will simply be ignored.
This filter leaves actual filtering to subclasses, which have to implement the
Filter.doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)
method.This generic filter base class has no dependency on the Spring
ApplicationContext
concept. Filters usually don't load their own context but rather access service beans from the Spring root application context, accessible via the filter'sServletContext
(seeWebApplicationContextUtils
).- 从以下版本开始:
- 06.12.2003
- 作者:
- Juergen Hoeller
- 另请参阅:
addRequiredProperty(java.lang.String)
,initFilterBean()
,Filter.doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)
构造器概要
构造器 构造器 说明 GenericFilterBean()
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 protected void
addRequiredProperty(String property)
Subclasses can invoke this method to specify that this property (which must match a JavaBean property they expose) is mandatory, and must be supplied as a config parameter.void
afterPropertiesSet()
Calls theinitFilterBean()
method that might contain custom initialization of a subclass.protected Environment
createEnvironment()
Create and return a newStandardServletEnvironment
.void
destroy()
Subclasses may override this to perform custom filter shutdown.Environment
getEnvironment()
Return theEnvironment
associated with this filter.FilterConfig
getFilterConfig()
Make the FilterConfig of this filter available, if any.protected String
getFilterName()
Make the name of this filter available to subclasses.protected ServletContext
getServletContext()
Make the ServletContext of this filter available to subclasses.void
init(FilterConfig filterConfig)
Standard way of initializing this filter.protected void
initBeanWrapper(BeanWrapper bw)
Initialize the BeanWrapper for this GenericFilterBean, possibly with custom editors.protected void
initFilterBean()
Subclasses may override this to perform custom initialization.void
setBeanName(String beanName)
Stores the bean name as defined in the Spring bean factory.void
setEnvironment(Environment environment)
Set theEnvironment
that this filter runs in.void
setServletContext(ServletContext servletContext)
Stores the ServletContext that the bean factory runs in.
构造器详细资料
GenericFilterBean
public GenericFilterBean()
方法详细资料
setBeanName
public void setBeanName(String beanName)
Stores the bean name as defined in the Spring bean factory.Only relevant in case of initialization as bean, to have a name as fallback to the filter name usually provided by a FilterConfig instance.
- 指定者:
setBeanName
在接口中BeanNameAware
- 参数:
beanName
- the name of the bean in the factory. Note that this name is the actual bean name used in the factory, which may differ from the originally specified name: in particular for inner bean names, the actual bean name might have been made unique through appending "#..." suffixes. Use theBeanFactoryUtils.originalBeanName(String)
method to extract the original bean name (without suffix), if desired.- 另请参阅:
BeanNameAware
,getFilterName()
setEnvironment
public void setEnvironment(Environment environment)
Set theEnvironment
that this filter runs in.Any environment set here overrides the
StandardServletEnvironment
provided by default.This
Environment
object is used only for resolving placeholders in resource paths passed into init-parameters for this filter. If no init-params are used, thisEnvironment
can be essentially ignored.- 指定者:
setEnvironment
在接口中EnvironmentAware
getEnvironment
public Environment getEnvironment()
Return theEnvironment
associated with this filter.If none specified, a default environment will be initialized via
createEnvironment()
.- 指定者:
getEnvironment
在接口中EnvironmentCapable
- 从以下版本开始:
- 4.3.9
createEnvironment
protected Environment createEnvironment()
Create and return a newStandardServletEnvironment
.Subclasses may override this in order to configure the environment or specialize the environment type returned.
- 从以下版本开始:
- 4.3.9
setServletContext
public void setServletContext(ServletContext servletContext)
Stores the ServletContext that the bean factory runs in.Only relevant in case of initialization as bean, to have a ServletContext as fallback to the context usually provided by a FilterConfig instance.
- 指定者:
setServletContext
在接口中ServletContextAware
- 参数:
servletContext
- ServletContext object to be used by this object- 另请参阅:
ServletContextAware
,getServletContext()
afterPropertiesSet
public void afterPropertiesSet() throws ServletException
Calls theinitFilterBean()
method that might contain custom initialization of a subclass.Only relevant in case of initialization as bean, where the standard
init(FilterConfig)
method won't be called.
destroy
public void destroy()
Subclasses may override this to perform custom filter shutdown.Note: This method will be called from standard filter destruction as well as filter bean destruction in a Spring application context.
This default implementation is empty.
- 指定者:
destroy
在接口中DisposableBean
- 指定者:
destroy
在接口中Filter
addRequiredProperty
protected final void addRequiredProperty(String property)
Subclasses can invoke this method to specify that this property (which must match a JavaBean property they expose) is mandatory, and must be supplied as a config parameter. This should be called from the constructor of a subclass.This method is only relevant in case of traditional initialization driven by a FilterConfig instance.
- 参数:
property
- name of the required property
init
public final void init(FilterConfig filterConfig) throws ServletException
Standard way of initializing this filter. Map config parameters onto bean properties of this filter, and invoke subclass initialization.- 指定者:
init
在接口中Filter
- 参数:
filterConfig
- the configuration for this filter- 抛出:
ServletException
- if bean properties are invalid (or required properties are missing), or if subclass initialization fails.- 另请参阅:
initFilterBean()
initBeanWrapper
protected void initBeanWrapper(BeanWrapper bw) throws BeansException
Initialize the BeanWrapper for this GenericFilterBean, possibly with custom editors.This default implementation is empty.
- 参数:
bw
- the BeanWrapper to initialize- 抛出:
BeansException
- if thrown by BeanWrapper methods- 另请参阅:
PropertyEditorRegistry.registerCustomEditor(java.lang.Class<?>, java.beans.PropertyEditor)
initFilterBean
protected void initFilterBean() throws ServletException
Subclasses may override this to perform custom initialization. All bean properties of this filter will have been set before this method is invoked.Note: This method will be called from standard filter initialization as well as filter bean initialization in a Spring application context. Filter name and ServletContext will be available in both cases.
This default implementation is empty.
- 抛出:
ServletException
- if subclass initialization fails- 另请参阅:
getFilterName()
,getServletContext()
getFilterConfig
public final FilterConfig getFilterConfig()
Make the FilterConfig of this filter available, if any. Analogous to GenericServlet'sgetServletConfig()
.Public to resemble the
getFilterConfig()
method of the Servlet Filter version that shipped with WebLogic 6.1.- 返回:
- the FilterConfig instance, or
null
if none available - 另请参阅:
GenericServlet.getServletConfig()
getFilterName
protected final String getFilterName()
Make the name of this filter available to subclasses. Analogous to GenericServlet'sgetServletName()
.Takes the FilterConfig's filter name by default. If initialized as bean in a Spring application context, it falls back to the bean name as defined in the bean factory.
- 返回:
- the filter name, or
null
if none available - 另请参阅:
GenericServlet.getServletName()
,FilterConfig.getFilterName()
,setBeanName(java.lang.String)
getServletContext
protected final ServletContext getServletContext()
Make the ServletContext of this filter available to subclasses. Analogous to GenericServlet'sgetServletContext()
.Takes the FilterConfig's ServletContext by default. If initialized as bean in a Spring application context, it falls back to the ServletContext that the bean factory runs in.
- 返回:
- the ServletContext instance, or
null
if none available - 另请参阅:
GenericServlet.getServletContext()
,FilterConfig.getServletContext()
,setServletContext(javax.servlet.ServletContext)