类 RequestContextFilter
- java.lang.Object
- org.springframework.web.filter.GenericFilterBean
- org.springframework.web.filter.OncePerRequestFilter
- org.springframework.web.filter.RequestContextFilter
- 所有已实现的接口:
Filter
,Aware
,BeanNameAware
,DisposableBean
,InitializingBean
,EnvironmentAware
,EnvironmentCapable
,ServletContextAware
public class RequestContextFilter extends OncePerRequestFilter
Servlet Filter that exposes the request to the current thread, through bothLocaleContextHolder
andRequestContextHolder
. To be registered as filter inweb.xml
.Alternatively, Spring's
RequestContextListener
and Spring'sDispatcherServlet
also expose the same request context to the current thread.This filter is mainly for use with third-party servlets, e.g. the JSF FacesServlet. Within Spring's own web support, DispatcherServlet's processing is perfectly sufficient.
- 从以下版本开始:
- 2.0
- 作者:
- Juergen Hoeller, Rod Johnson, Rossen Stoyanchev
- 另请参阅:
LocaleContextHolder
,RequestContextHolder
,RequestContextListener
,DispatcherServlet
字段概要
从类继承的字段 org.springframework.web.filter.OncePerRequestFilter
ALREADY_FILTERED_SUFFIX
从类继承的字段 org.springframework.web.filter.GenericFilterBean
logger
构造器概要
构造器 构造器 说明 RequestContextFilter()
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 protected void
doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
Same contract as fordoFilter
, but guaranteed to be just invoked once per request within a single request thread.void
setThreadContextInheritable(boolean threadContextInheritable)
Set whether to expose the LocaleContext and RequestAttributes as inheritable for child threads (using anInheritableThreadLocal
).protected boolean
shouldNotFilterAsyncDispatch()
Returns "false" so that the filter may set up the request context in each asynchronously dispatched thread.protected boolean
shouldNotFilterErrorDispatch()
Returns "false" so that the filter may set up the request context in an error dispatch.从类继承的方法 org.springframework.web.filter.OncePerRequestFilter
doFilter, getAlreadyFilteredAttributeName, isAsyncDispatch, isAsyncStarted, shouldNotFilter
从类继承的方法 org.springframework.web.filter.GenericFilterBean
addRequiredProperty, afterPropertiesSet, createEnvironment, destroy, getEnvironment, getFilterConfig, getFilterName, getServletContext, init, initBeanWrapper, initFilterBean, setBeanName, setEnvironment, setServletContext
构造器详细资料
RequestContextFilter
public RequestContextFilter()
方法详细资料
setThreadContextInheritable
public void setThreadContextInheritable(boolean threadContextInheritable)
Set whether to expose the LocaleContext and RequestAttributes as inheritable for child threads (using anInheritableThreadLocal
).Default is "false", to avoid side effects on spawned background threads. Switch this to "true" to enable inheritance for custom child threads which are spawned during request processing and only used for this request (that is, ending after their initial task, without reuse of the thread).
WARNING: Do not use inheritance for child threads if you are accessing a thread pool which is configured to potentially add new threads on demand (e.g. a JDK
ThreadPoolExecutor
), since this will expose the inherited context to such a pooled thread.
shouldNotFilterAsyncDispatch
protected boolean shouldNotFilterAsyncDispatch()
Returns "false" so that the filter may set up the request context in each asynchronously dispatched thread.
shouldNotFilterErrorDispatch
protected boolean shouldNotFilterErrorDispatch()
Returns "false" so that the filter may set up the request context in an error dispatch.
doFilterInternal
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException
从类复制的说明:OncePerRequestFilter
Same contract as fordoFilter
, but guaranteed to be just invoked once per request within a single request thread. SeeOncePerRequestFilter.shouldNotFilterAsyncDispatch()
for details.Provides HttpServletRequest and HttpServletResponse arguments instead of the default ServletRequest and ServletResponse ones.