类 FilterRegistrationBean
- java.lang.Object
- org.springframework.boot.web.servlet.RegistrationBean
- org.springframework.boot.web.servlet.FilterRegistrationBean
- 所有已实现的接口:
ServletContextInitializer
,org.springframework.core.Ordered
public class FilterRegistrationBean extends RegistrationBean
AServletContextInitializer
to registerFilter
s in a Servlet 3.0+ container. Similar to theregistration
features provided byServletContext
but with a Spring Bean friendly design.The
Filter
must be specified before callingServletContextInitializer.onStartup(ServletContext)
. Registrations can be associated withURL patterns
and/or servlets (either byname
or via aServletRegistrationBean
s. When no URL pattern or servlets are specified the filter will be associated to '/*'. The filter name will be deduced if not specified.- 从以下版本开始:
- 1.4.0
- 另请参阅:
ServletContextInitializer
,ServletContext.addFilter(String, Filter)
,DelegatingFilterProxyRegistrationBean
字段概要
字段 修饰符和类型 字段 说明 static int
REQUEST_WRAPPER_FILTER_MAX_ORDER
Filters that wrap the servlet request should be ordered less than or equal to this.
构造器概要
构造器 构造器 说明 FilterRegistrationBean()
Create a newFilterRegistrationBean
instance.FilterRegistrationBean(javax.servlet.Filter filter, ServletRegistrationBean... servletRegistrationBeans)
Create a newFilterRegistrationBean
instance to be registered with the specifiedServletRegistrationBean
s.
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 void
addServletNames(String... servletNames)
Add servlet names for the filter.void
addServletRegistrationBeans(ServletRegistrationBean... servletRegistrationBeans)
AddServletRegistrationBean
s for the filter.void
addUrlPatterns(String... urlPatterns)
Add URL patterns that the filter will be registered against.protected void
configure(javax.servlet.FilterRegistration.Dynamic registration)
Configure registration settings.javax.servlet.Filter
getFilter()
Return theFilter
to be registered.Collection<String>
getServletNames()
Return a mutable collection of servlet names that the filter will be registered against.Collection<ServletRegistrationBean>
getServletRegistrationBeans()
Return a mutable collection of theServletRegistrationBean
that the filter will be registered against.Collection<String>
getUrlPatterns()
Return a mutable collection of URL patterns that the filter will be registered against.boolean
isMatchAfter()
Return if filter mappings should be matched after any declared Filter mappings of the ServletContext.void
onStartup(javax.servlet.ServletContext servletContext)
Configure the givenServletContext
with any servlets, filters, listeners context-params and attributes necessary for initialization.void
setDispatcherTypes(EnumSet<javax.servlet.DispatcherType> dispatcherTypes)
Sets the dispatcher types that should be used with the registration.void
setDispatcherTypes(javax.servlet.DispatcherType first, javax.servlet.DispatcherType... rest)
Convenience method toset dispatcher types
using the specified elements.void
setFilter(javax.servlet.Filter filter)
Set the filter to be registered.void
setMatchAfter(boolean matchAfter)
Set if the filter mappings should be matched after any declared filter mappings of the ServletContext.void
setServletNames(Collection<String> servletNames)
Set servlet names that the filter will be registered against.void
setServletRegistrationBeans(Collection<? extends ServletRegistrationBean> servletRegistrationBeans)
SetServletRegistrationBean
s that the filter will be registered against.void
setUrlPatterns(Collection<String> urlPatterns)
Set the URL patterns that the filter will be registered against.从类继承的方法 org.springframework.boot.web.servlet.RegistrationBean
addInitParameter, configure, getInitParameters, getOrDeduceName, getOrder, isAsyncSupported, isEnabled, setAsyncSupported, setEnabled, setInitParameters, setName, setOrder
字段详细资料
REQUEST_WRAPPER_FILTER_MAX_ORDER
public static final int REQUEST_WRAPPER_FILTER_MAX_ORDER
Filters that wrap the servlet request should be ordered less than or equal to this.- 另请参阅:
- 常量字段值
构造器详细资料
FilterRegistrationBean
public FilterRegistrationBean()
Create a newFilterRegistrationBean
instance.
FilterRegistrationBean
public FilterRegistrationBean(javax.servlet.Filter filter, ServletRegistrationBean... servletRegistrationBeans)
Create a newFilterRegistrationBean
instance to be registered with the specifiedServletRegistrationBean
s.- 参数:
filter
- the filter to registerservletRegistrationBeans
- associateServletRegistrationBean
s
方法详细资料
getFilter
public javax.servlet.Filter getFilter()
Return theFilter
to be registered.- 返回:
- the filter
setFilter
public void setFilter(javax.servlet.Filter filter)
Set the filter to be registered.- 参数:
filter
- the filter
setServletRegistrationBeans
public void setServletRegistrationBeans(Collection<? extends ServletRegistrationBean> servletRegistrationBeans)
SetServletRegistrationBean
s that the filter will be registered against.- 参数:
servletRegistrationBeans
- the Servlet registration beans
getServletRegistrationBeans
public Collection<ServletRegistrationBean> getServletRegistrationBeans()
Return a mutable collection of theServletRegistrationBean
that the filter will be registered against.ServletRegistrationBean
s.- 返回:
- the Servlet registration beans
- 另请参阅:
setServletNames(java.util.Collection<java.lang.String>)
,setUrlPatterns(java.util.Collection<java.lang.String>)
addServletRegistrationBeans
public void addServletRegistrationBeans(ServletRegistrationBean... servletRegistrationBeans)
AddServletRegistrationBean
s for the filter.- 参数:
servletRegistrationBeans
- the servlet registration beans to add- 另请参阅:
setServletRegistrationBeans(java.util.Collection<? extends org.springframework.boot.web.servlet.ServletRegistrationBean>)
setServletNames
public void setServletNames(Collection<String> servletNames)
Set servlet names that the filter will be registered against. This will replace any previously specified servlet names.
getServletNames
public Collection<String> getServletNames()
Return a mutable collection of servlet names that the filter will be registered against.- 返回:
- the servlet names
addServletNames
public void addServletNames(String... servletNames)
Add servlet names for the filter.- 参数:
servletNames
- the servlet names to add
setUrlPatterns
public void setUrlPatterns(Collection<String> urlPatterns)
Set the URL patterns that the filter will be registered against. This will replace any previously specified URL patterns.
getUrlPatterns
public Collection<String> getUrlPatterns()
Return a mutable collection of URL patterns that the filter will be registered against.- 返回:
- the URL patterns
addUrlPatterns
public void addUrlPatterns(String... urlPatterns)
Add URL patterns that the filter will be registered against.- 参数:
urlPatterns
- the URL patterns
setDispatcherTypes
public void setDispatcherTypes(javax.servlet.DispatcherType first, javax.servlet.DispatcherType... rest)
Convenience method toset dispatcher types
using the specified elements.- 参数:
first
- the first dispatcher typerest
- additional dispatcher types
setDispatcherTypes
public void setDispatcherTypes(EnumSet<javax.servlet.DispatcherType> dispatcherTypes)
Sets the dispatcher types that should be used with the registration. If not specified the types will be deduced based on the value ofRegistrationBean.isAsyncSupported()
.- 参数:
dispatcherTypes
- the dispatcher types
setMatchAfter
public void setMatchAfter(boolean matchAfter)
Set if the filter mappings should be matched after any declared filter mappings of the ServletContext. Defaults tofalse
indicating the filters are supposed to be matched before any declared filter mappings of the ServletContext.- 参数:
matchAfter
- if filter mappings are matched after
isMatchAfter
public boolean isMatchAfter()
Return if filter mappings should be matched after any declared Filter mappings of the ServletContext.- 返回:
- if filter mappings are matched after
onStartup
public void onStartup(javax.servlet.ServletContext servletContext) throws javax.servlet.ServletException
从接口复制的说明:ServletContextInitializer
Configure the givenServletContext
with any servlets, filters, listeners context-params and attributes necessary for initialization.- 参数:
servletContext
- theServletContext
to initialize- 抛出:
javax.servlet.ServletException
- if any call against the givenServletContext
throws aServletException
configure
protected void configure(javax.servlet.FilterRegistration.Dynamic registration)
Configure registration settings. Subclasses can override this method to perform additional configuration if required.- 参数:
registration
- the registration