public class FilterRegistrationBean extends RegistrationBean
ServletContextInitializer
to register Filter
s in a Servlet 3.0+
container. Similar to the registration
features provided by ServletContext
but with a Spring Bean friendly design.
The Filter
must be specified before calling
onStartup(ServletContext)
. Registrations can be associated with
URL patterns
and/or servlets (either by
name
or via a ServletRegistrationBean
s. When no URL pattern or servlets are specified the filter
will be associated to '/*'. The filter name will be deduced if not specified.
ServletContextInitializer
,
ServletContext#addFilter(String, Filter)
Constructor and Description |
---|
FilterRegistrationBean()
Create a new
FilterRegistrationBean instance. |
FilterRegistrationBean(Filter filter,
ServletRegistrationBean... servletRegistrationBeans)
Create a new
FilterRegistrationBean instance to be registered with the
specified ServletRegistrationBean s. |
Modifier and Type | Method and Description |
---|---|
void |
addServletNames(String... servletNames)
Add servlet names for the filter.
|
void |
addServletRegistrationBeans(ServletRegistrationBean... servletRegistrationBeans)
Add
ServletRegistrationBean s for the filter. |
void |
addUrlPatterns(String... urlPatterns)
Add URL patterns that the filter will be registered against.
|
protected void |
configure(FilterRegistration.Dynamic registration)
Configure registration settings.
|
protected Filter |
getFilter()
Returns the filter being 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 the
ServletRegistrationBean 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(ServletContext servletContext)
Configure the given
ServletContext with any servlets, filters, listeners
context-params and attributes necessary for initialization. |
void |
setFilter(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)
Set
ServletRegistrationBean s that the filter will be registered against. |
void |
setUrlPatterns(Collection<String> urlPatterns)
Set the URL patterns that the filter will be registered against.
|
addInitParameter, getInitParameters, getOrDeduceName, isAsyncSupported, setAsyncSupported, setInitParameters, setName
public FilterRegistrationBean()
FilterRegistrationBean
instance.public FilterRegistrationBean(Filter filter, ServletRegistrationBean... servletRegistrationBeans)
FilterRegistrationBean
instance to be registered with the
specified ServletRegistrationBean
s.filter
- the filter to registerservletRegistrationBeans
- associate ServletRegistrationBean
sprotected Filter getFilter()
public void setFilter(Filter filter)
public void setServletRegistrationBeans(Collection<? extends ServletRegistrationBean> servletRegistrationBeans)
ServletRegistrationBean
s that the filter will be registered against.servletRegistrationBeans
- the Servlet registration beanspublic Collection<ServletRegistrationBean> getServletRegistrationBeans()
ServletRegistrationBean
that the filter
will be registered against. ServletRegistrationBean
s.setServletNames(java.util.Collection<java.lang.String>)
,
setUrlPatterns(java.util.Collection<java.lang.String>)
public void addServletRegistrationBeans(ServletRegistrationBean... servletRegistrationBeans)
ServletRegistrationBean
s for the filter.servletRegistrationBeans
- the servlet registration beans to addsetServletRegistrationBeans(java.util.Collection<? extends org.springframework.boot.context.embedded.ServletRegistrationBean>)
public void setServletNames(Collection<String> servletNames)
servletNames
- the servlet namessetServletRegistrationBeans(java.util.Collection<? extends org.springframework.boot.context.embedded.ServletRegistrationBean>)
,
setUrlPatterns(java.util.Collection<java.lang.String>)
public Collection<String> getServletNames()
public void addServletNames(String... servletNames)
servletNames
- the servlet names to addpublic void setUrlPatterns(Collection<String> urlPatterns)
urlPatterns
- the URL patternssetServletRegistrationBeans(java.util.Collection<? extends org.springframework.boot.context.embedded.ServletRegistrationBean>)
,
setServletNames(java.util.Collection<java.lang.String>)
public Collection<String> getUrlPatterns()
public void addUrlPatterns(String... urlPatterns)
urlPatterns
- the URL patternspublic void setMatchAfter(boolean matchAfter)
false
indicating the filters are supposed
to be matched before any declared filter mappings of the ServletContext.public boolean isMatchAfter()
public void onStartup(ServletContext servletContext) throws ServletException
ServletContextInitializer
ServletContext
with any servlets, filters, listeners
context-params and attributes necessary for initialization.servletContext
- the ServletContext
to initializeServletException
- if any call against the given ServletContext
throws a ServletException
protected void configure(FilterRegistration.Dynamic registration)
configure
in class RegistrationBean
Copyright © 2013. All rights reserved.