类 RequestMappingHandlerAdapter
- java.lang.Object
- org.springframework.context.support.ApplicationObjectSupport
- org.springframework.web.context.support.WebApplicationObjectSupport
- org.springframework.web.servlet.support.WebContentGenerator
- org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter
- org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter
- 所有已实现的接口:
Aware,BeanFactoryAware,InitializingBean,ApplicationContextAware,Ordered,ServletContextAware,HandlerAdapter
public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter implements BeanFactoryAware, InitializingBean
Extension ofAbstractHandlerMethodAdapterthat supports@RequestMappingannotatedHandlerMethods.Support for custom argument and return value types can be added via
setCustomArgumentResolvers(java.util.List<org.springframework.web.method.support.HandlerMethodArgumentResolver>)andsetCustomReturnValueHandlers(java.util.List<org.springframework.web.method.support.HandlerMethodReturnValueHandler>), or alternatively, to re-configure all argument and return value types, usesetArgumentResolvers(java.util.List<org.springframework.web.method.support.HandlerMethodArgumentResolver>)andsetReturnValueHandlers(java.util.List<org.springframework.web.method.support.HandlerMethodReturnValueHandler>).- 从以下版本开始:
- 3.1
- 作者:
- Rossen Stoyanchev, Juergen Hoeller
- 另请参阅:
HandlerMethodArgumentResolver,HandlerMethodReturnValueHandler
字段概要
字段 修饰符和类型 字段 说明 static ReflectionUtils.MethodFilterINIT_BINDER_METHODSMethodFilter that matches@InitBindermethods.static ReflectionUtils.MethodFilterMODEL_ATTRIBUTE_METHODSMethodFilter that matches@ModelAttributemethods.从类继承的字段 org.springframework.web.servlet.support.WebContentGenerator
HEADER_CACHE_CONTROL, METHOD_GET, METHOD_HEAD, METHOD_POST
从类继承的字段 org.springframework.context.support.ApplicationObjectSupport
logger
从接口继承的字段 org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
构造器概要
构造器 构造器 说明 RequestMappingHandlerAdapter()
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 voidafterPropertiesSet()Invoked by the containingBeanFactoryafter it has set all bean properties and satisfiedBeanFactoryAware,ApplicationContextAwareetc.protected InitBinderDataBinderFactorycreateDataBinderFactory(List<InvocableHandlerMethod> binderMethods)Template method to create a new InitBinderDataBinderFactory instance.protected ServletInvocableHandlerMethodcreateInvocableHandlerMethod(HandlerMethod handlerMethod)Create aServletInvocableHandlerMethodfrom the givenHandlerMethoddefinition.List<HandlerMethodArgumentResolver>getArgumentResolvers()Return the configured argument resolvers, or possiblynullif not initialized yet viaafterPropertiesSet().protected ConfigurableBeanFactorygetBeanFactory()Return the owning factory of this bean instance, ornullif none.List<HandlerMethodArgumentResolver>getCustomArgumentResolvers()Return the custom argument resolvers, ornull.List<HandlerMethodReturnValueHandler>getCustomReturnValueHandlers()Return the custom return value handlers, ornull.List<HandlerMethodArgumentResolver>getInitBinderArgumentResolvers()Return the argument resolvers for@InitBindermethods, or possiblynullif not initialized yet viaafterPropertiesSet().protected longgetLastModifiedInternal(HttpServletRequest request, HandlerMethod handlerMethod)This implementation always returns -1.List<HttpMessageConverter<?>>getMessageConverters()Return the configured message body converters.List<ModelAndViewResolver>getModelAndViewResolvers()Return the configuredModelAndViewResolvers, ornull.ReactiveAdapterRegistrygetReactiveAdapterRegistry()Return the configured reactive type registry of adapters.List<HandlerMethodReturnValueHandler>getReturnValueHandlers()Return the configured handlers, or possiblynullif not initialized yet viaafterPropertiesSet().WebBindingInitializergetWebBindingInitializer()Return the configured WebBindingInitializer, ornullif none.protected ModelAndViewhandleInternal(HttpServletRequest request, HttpServletResponse response, HandlerMethod handlerMethod)Use the given handler method to handle the request.protected ModelAndViewinvokeHandlerMethod(HttpServletRequest request, HttpServletResponse response, HandlerMethod handlerMethod)Invoke theRequestMappinghandler method preparing aModelAndViewif view resolution is required.voidsetArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers)Configure the complete list of supported argument types thus overriding the resolvers that would otherwise be configured by default.voidsetAsyncRequestTimeout(long timeout)Specify the amount of time, in milliseconds, before concurrent handling should time out.voidsetBeanFactory(BeanFactory beanFactory)AConfigurableBeanFactoryis expected for resolving expressions in method argument default values.voidsetCacheSecondsForSessionAttributeHandlers(int cacheSecondsForSessionAttributeHandlers)Cache content produced by@SessionAttributesannotated handlers for the given number of seconds.voidsetCallableInterceptors(List<CallableProcessingInterceptor> interceptors)ConfigureCallableProcessingInterceptor's to register on async requests.voidsetContentNegotiationManager(ContentNegotiationManager contentNegotiationManager)Set theContentNegotiationManagerto use to determine requested media types.voidsetCustomArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers)Provide resolvers for custom argument types.voidsetCustomReturnValueHandlers(List<HandlerMethodReturnValueHandler> returnValueHandlers)Provide handlers for custom return value types.voidsetDeferredResultInterceptors(List<DeferredResultProcessingInterceptor> interceptors)ConfigureDeferredResultProcessingInterceptor's to register on async requests.voidsetIgnoreDefaultModelOnRedirect(boolean ignoreDefaultModelOnRedirect)By default the content of the "default" model is used both during rendering and redirect scenarios.voidsetInitBinderArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers)Configure the supported argument types in@InitBindermethods.voidsetMessageConverters(List<HttpMessageConverter<?>> messageConverters)Provide the converters to use in argument resolvers and return value handlers that support reading and/or writing to the body of the request and response.voidsetModelAndViewResolvers(List<ModelAndViewResolver> modelAndViewResolvers)Provide customModelAndViewResolvers.voidsetParameterNameDiscoverer(ParameterNameDiscoverer parameterNameDiscoverer)Set the ParameterNameDiscoverer to use for resolving method parameter names if needed (e.g. for default attribute names).voidsetReactiveAdapterRegistry(ReactiveAdapterRegistry reactiveAdapterRegistry)Configure the registry for reactive library types to be supported as return values from controller methods.voidsetRequestBodyAdvice(List<RequestBodyAdvice> requestBodyAdvice)Add one or moreRequestBodyAdviceinstances to intercept the request before it is read and converted for@RequestBodyandHttpEntitymethod arguments.voidsetResponseBodyAdvice(List<ResponseBodyAdvice<?>> responseBodyAdvice)Add one or moreResponseBodyAdviceinstances to intercept the response before@ResponseBodyorResponseEntityreturn values are written to the response body.voidsetReturnValueHandlers(List<HandlerMethodReturnValueHandler> returnValueHandlers)Configure the complete list of supported return value types thus overriding handlers that would otherwise be configured by default.voidsetSessionAttributeStore(SessionAttributeStore sessionAttributeStore)Specify the strategy to store session attributes with.voidsetSynchronizeOnSession(boolean synchronizeOnSession)Set if controller execution should be synchronized on the session, to serialize parallel invocations from the same client.voidsetTaskExecutor(AsyncTaskExecutor taskExecutor)Set the defaultAsyncTaskExecutorto use when a controller method return aCallable.voidsetWebBindingInitializer(WebBindingInitializer webBindingInitializer)Provide a WebBindingInitializer with "global" initialization to apply to every DataBinder instance.protected booleansupportsInternal(HandlerMethod handlerMethod)Always returntruesince any method argument and return value type will be processed in some way.从类继承的方法 org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter
getLastModified, getOrder, handle, setOrder, supports
从类继承的方法 org.springframework.web.servlet.support.WebContentGenerator
applyCacheControl, applyCacheSeconds, applyCacheSeconds, cacheForSeconds, cacheForSeconds, checkAndPrepare, checkAndPrepare, checkRequest, getAllowHeader, getCacheControl, getCacheSeconds, getSupportedMethods, getVaryByRequestHeaders, isAlwaysMustRevalidate, isRequireSession, isUseCacheControlHeader, isUseCacheControlNoStore, isUseExpiresHeader, prepareResponse, preventCaching, setAlwaysMustRevalidate, setCacheControl, setCacheSeconds, setRequireSession, setSupportedMethods, setUseCacheControlHeader, setUseCacheControlNoStore, setUseExpiresHeader, setVaryByRequestHeaders
从类继承的方法 org.springframework.web.context.support.WebApplicationObjectSupport
getServletContext, getTempDir, getWebApplicationContext, initApplicationContext, initServletContext, isContextRequired, setServletContext
从类继承的方法 org.springframework.context.support.ApplicationObjectSupport
getApplicationContext, getMessageSourceAccessor, initApplicationContext, obtainApplicationContext, requiredContextClass, setApplicationContext
字段详细资料
INIT_BINDER_METHODS
public static final ReflectionUtils.MethodFilter INIT_BINDER_METHODS
MethodFilter that matches@InitBindermethods.
MODEL_ATTRIBUTE_METHODS
public static final ReflectionUtils.MethodFilter MODEL_ATTRIBUTE_METHODS
MethodFilter that matches@ModelAttributemethods.
构造器详细资料
RequestMappingHandlerAdapter
public RequestMappingHandlerAdapter()
方法详细资料
setCustomArgumentResolvers
public void setCustomArgumentResolvers(@Nullable List<HandlerMethodArgumentResolver> argumentResolvers)
Provide resolvers for custom argument types. Custom resolvers are ordered after built-in ones. To override the built-in support for argument resolution usesetArgumentResolvers(java.util.List<org.springframework.web.method.support.HandlerMethodArgumentResolver>)instead.
getCustomArgumentResolvers
@Nullable public List<HandlerMethodArgumentResolver> getCustomArgumentResolvers()
Return the custom argument resolvers, ornull.
setArgumentResolvers
public void setArgumentResolvers(@Nullable List<HandlerMethodArgumentResolver> argumentResolvers)
Configure the complete list of supported argument types thus overriding the resolvers that would otherwise be configured by default.
getArgumentResolvers
@Nullable public List<HandlerMethodArgumentResolver> getArgumentResolvers()
Return the configured argument resolvers, or possiblynullif not initialized yet viaafterPropertiesSet().
setInitBinderArgumentResolvers
public void setInitBinderArgumentResolvers(@Nullable List<HandlerMethodArgumentResolver> argumentResolvers)
Configure the supported argument types in@InitBindermethods.
getInitBinderArgumentResolvers
@Nullable public List<HandlerMethodArgumentResolver> getInitBinderArgumentResolvers()
Return the argument resolvers for@InitBindermethods, or possiblynullif not initialized yet viaafterPropertiesSet().
setCustomReturnValueHandlers
public void setCustomReturnValueHandlers(@Nullable List<HandlerMethodReturnValueHandler> returnValueHandlers)
Provide handlers for custom return value types. Custom handlers are ordered after built-in ones. To override the built-in support for return value handling usesetReturnValueHandlers(java.util.List<org.springframework.web.method.support.HandlerMethodReturnValueHandler>).
getCustomReturnValueHandlers
@Nullable public List<HandlerMethodReturnValueHandler> getCustomReturnValueHandlers()
Return the custom return value handlers, ornull.
setReturnValueHandlers
public void setReturnValueHandlers(@Nullable List<HandlerMethodReturnValueHandler> returnValueHandlers)
Configure the complete list of supported return value types thus overriding handlers that would otherwise be configured by default.
getReturnValueHandlers
@Nullable public List<HandlerMethodReturnValueHandler> getReturnValueHandlers()
Return the configured handlers, or possiblynullif not initialized yet viaafterPropertiesSet().
setModelAndViewResolvers
public void setModelAndViewResolvers(@Nullable List<ModelAndViewResolver> modelAndViewResolvers)
Provide customModelAndViewResolvers.Note: This method is available for backwards compatibility only. However, it is recommended to re-write a
ModelAndViewResolverasHandlerMethodReturnValueHandler. An adapter between the two interfaces is not possible since theHandlerMethodReturnValueHandler.supportsReturnType(org.springframework.core.MethodParameter)method cannot be implemented. HenceModelAndViewResolvers are limited to always being invoked at the end after all other return value handlers have been given a chance.A
HandlerMethodReturnValueHandlerprovides better access to the return type and controller method information and can be ordered freely relative to other return value handlers.
getModelAndViewResolvers
@Nullable public List<ModelAndViewResolver> getModelAndViewResolvers()
Return the configuredModelAndViewResolvers, ornull.
setContentNegotiationManager
public void setContentNegotiationManager(ContentNegotiationManager contentNegotiationManager)
Set theContentNegotiationManagerto use to determine requested media types. If not set, the default constructor is used.
setMessageConverters
public void setMessageConverters(List<HttpMessageConverter<?>> messageConverters)
Provide the converters to use in argument resolvers and return value handlers that support reading and/or writing to the body of the request and response.
getMessageConverters
public List<HttpMessageConverter<?>> getMessageConverters()
Return the configured message body converters.
setRequestBodyAdvice
public void setRequestBodyAdvice(@Nullable List<RequestBodyAdvice> requestBodyAdvice)
Add one or moreRequestBodyAdviceinstances to intercept the request before it is read and converted for@RequestBodyandHttpEntitymethod arguments.
setResponseBodyAdvice
public void setResponseBodyAdvice(@Nullable List<ResponseBodyAdvice<?>> responseBodyAdvice)
Add one or moreResponseBodyAdviceinstances to intercept the response before@ResponseBodyorResponseEntityreturn values are written to the response body.
setWebBindingInitializer
public void setWebBindingInitializer(@Nullable WebBindingInitializer webBindingInitializer)
Provide a WebBindingInitializer with "global" initialization to apply to every DataBinder instance.
getWebBindingInitializer
@Nullable public WebBindingInitializer getWebBindingInitializer()
Return the configured WebBindingInitializer, ornullif none.
setTaskExecutor
public void setTaskExecutor(AsyncTaskExecutor taskExecutor)
Set the defaultAsyncTaskExecutorto use when a controller method return aCallable. Controller methods can override this default on a per-request basis by returning anWebAsyncTask.By default a
SimpleAsyncTaskExecutorinstance is used. It's recommended to change that default in production as the simple executor does not re-use threads.
setAsyncRequestTimeout
public void setAsyncRequestTimeout(long timeout)
Specify the amount of time, in milliseconds, before concurrent handling should time out. In Servlet 3, the timeout begins after the main request processing thread has exited and ends when the request is dispatched again for further processing of the concurrently produced result.If this value is not set, the default timeout of the underlying implementation is used.
- 参数:
timeout- the timeout value in milliseconds
setCallableInterceptors
public void setCallableInterceptors(List<CallableProcessingInterceptor> interceptors)
ConfigureCallableProcessingInterceptor's to register on async requests.- 参数:
interceptors- the interceptors to register
setDeferredResultInterceptors
public void setDeferredResultInterceptors(List<DeferredResultProcessingInterceptor> interceptors)
ConfigureDeferredResultProcessingInterceptor's to register on async requests.- 参数:
interceptors- the interceptors to register
setReactiveAdapterRegistry
public void setReactiveAdapterRegistry(ReactiveAdapterRegistry reactiveAdapterRegistry)
Configure the registry for reactive library types to be supported as return values from controller methods.- 从以下版本开始:
- 5.0.5
getReactiveAdapterRegistry
public ReactiveAdapterRegistry getReactiveAdapterRegistry()
Return the configured reactive type registry of adapters.- 从以下版本开始:
- 5.0
setIgnoreDefaultModelOnRedirect
public void setIgnoreDefaultModelOnRedirect(boolean ignoreDefaultModelOnRedirect)
By default the content of the "default" model is used both during rendering and redirect scenarios. Alternatively a controller method can declare aRedirectAttributesargument and use it to provide attributes for a redirect.Setting this flag to
trueguarantees the "default" model is never used in a redirect scenario even if a RedirectAttributes argument is not declared. Setting it tofalsemeans the "default" model may be used in a redirect if the controller method doesn't declare a RedirectAttributes argument.The default setting is
falsebut new applications should consider setting it totrue.- 另请参阅:
RedirectAttributes
setSessionAttributeStore
public void setSessionAttributeStore(SessionAttributeStore sessionAttributeStore)
Specify the strategy to store session attributes with. The default isDefaultSessionAttributeStore, storing session attributes in the HttpSession with the same attribute name as in the model.
setCacheSecondsForSessionAttributeHandlers
public void setCacheSecondsForSessionAttributeHandlers(int cacheSecondsForSessionAttributeHandlers)
Cache content produced by@SessionAttributesannotated handlers for the given number of seconds.Possible values are:
- -1: no generation of cache-related headers
- 0 (default value): "Cache-Control: no-store" will prevent caching
- 1 or higher: "Cache-Control: max-age=seconds" will ask to cache content; not advised when dealing with session attributes
In contrast to the "cacheSeconds" property which will apply to all general handlers (but not to
@SessionAttributesannotated handlers), this setting will apply to@SessionAttributeshandlers only.
setSynchronizeOnSession
public void setSynchronizeOnSession(boolean synchronizeOnSession)
Set if controller execution should be synchronized on the session, to serialize parallel invocations from the same client.More specifically, the execution of the
handleRequestInternalmethod will get synchronized if this flag is "true". The best available session mutex will be used for the synchronization; ideally, this will be a mutex exposed by HttpSessionMutexListener.The session mutex is guaranteed to be the same object during the entire lifetime of the session, available under the key defined by the
SESSION_MUTEX_ATTRIBUTEconstant. It serves as a safe reference to synchronize on for locking on the current session.In many cases, the HttpSession reference itself is a safe mutex as well, since it will always be the same object reference for the same active logical session. However, this is not guaranteed across different servlet containers; the only 100% safe way is a session mutex.
setParameterNameDiscoverer
public void setParameterNameDiscoverer(ParameterNameDiscoverer parameterNameDiscoverer)
Set the ParameterNameDiscoverer to use for resolving method parameter names if needed (e.g. for default attribute names).Default is a
DefaultParameterNameDiscoverer.
setBeanFactory
public void setBeanFactory(BeanFactory beanFactory)
AConfigurableBeanFactoryis expected for resolving expressions in method argument default values.- 指定者:
setBeanFactory在接口中BeanFactoryAware- 参数:
beanFactory- owning BeanFactory (nevernull). The bean can immediately call methods on the factory.- 另请参阅:
BeanInitializationException
getBeanFactory
@Nullable protected ConfigurableBeanFactory getBeanFactory()
Return the owning factory of this bean instance, ornullif none.
afterPropertiesSet
public void afterPropertiesSet()
从接口复制的说明:InitializingBeanInvoked by the containingBeanFactoryafter it has set all bean properties and satisfiedBeanFactoryAware,ApplicationContextAwareetc.This method allows the bean instance to perform validation of its overall configuration and final initialization when all bean properties have been set.
- 指定者:
afterPropertiesSet在接口中InitializingBean
supportsInternal
protected boolean supportsInternal(HandlerMethod handlerMethod)
Always returntruesince any method argument and return value type will be processed in some way. A method argument not recognized by any HandlerMethodArgumentResolver is interpreted as a request parameter if it is a simple type, or as a model attribute otherwise. A return value not recognized by any HandlerMethodReturnValueHandler will be interpreted as a model attribute.- 指定者:
supportsInternal在类中AbstractHandlerMethodAdapter- 参数:
handlerMethod- the handler method to check- 返回:
- whether or not this adapter can adapt the given method
handleInternal
protected ModelAndView handleInternal(HttpServletRequest request, HttpServletResponse response, HandlerMethod handlerMethod) throws Exception
从类复制的说明:AbstractHandlerMethodAdapterUse the given handler method to handle the request.- 指定者:
handleInternal在类中AbstractHandlerMethodAdapter- 参数:
request- current HTTP requestresponse- current HTTP responsehandlerMethod- handler method to use. This object must have previously been passed to theAbstractHandlerMethodAdapter.supportsInternal(HandlerMethod)this interface, which must have returnedtrue.- 返回:
- a ModelAndView object with the name of the view and the required model data, or
nullif the request has been handled directly - 抛出:
Exception- in case of errors
getLastModifiedInternal
protected long getLastModifiedInternal(HttpServletRequest request, HandlerMethod handlerMethod)
This implementation always returns -1. An@RequestMappingmethod can calculate the lastModified value, callWebRequest.checkNotModified(long), and returnnullif the result of that call istrue.- 指定者:
getLastModifiedInternal在类中AbstractHandlerMethodAdapter- 参数:
request- current HTTP requesthandlerMethod- handler method to use- 返回:
- the lastModified value for the given handler
invokeHandlerMethod
@Nullable protected ModelAndView invokeHandlerMethod(HttpServletRequest request, HttpServletResponse response, HandlerMethod handlerMethod) throws Exception
Invoke theRequestMappinghandler method preparing aModelAndViewif view resolution is required.- 抛出:
Exception- 从以下版本开始:
- 4.2
- 另请参阅:
createInvocableHandlerMethod(HandlerMethod)
createInvocableHandlerMethod
protected ServletInvocableHandlerMethod createInvocableHandlerMethod(HandlerMethod handlerMethod)
Create aServletInvocableHandlerMethodfrom the givenHandlerMethoddefinition.- 参数:
handlerMethod- theHandlerMethoddefinition- 返回:
- the corresponding
ServletInvocableHandlerMethod(or custom subclass thereof) - 从以下版本开始:
- 4.2
createDataBinderFactory
protected InitBinderDataBinderFactory createDataBinderFactory(List<InvocableHandlerMethod> binderMethods) throws Exception
Template method to create a new InitBinderDataBinderFactory instance.The default implementation creates a ServletRequestDataBinderFactory. This can be overridden for custom ServletRequestDataBinder subclasses.
- 参数:
binderMethods-@InitBindermethods- 返回:
- the InitBinderDataBinderFactory instance to use
- 抛出:
Exception- in case of invalid state or arguments