public class AnnotationMethodHandlerAdapter
extends org.springframework.web.servlet.support.WebContentGenerator
implements org.springframework.web.servlet.HandlerAdapter, org.springframework.core.Ordered, org.springframework.beans.factory.BeanFactoryAware
HandlerAdapter
interface that maps handler methods based on HTTP paths, HTTP methods and
request parameters expressed through the RequestMapping annotation.
Supports request parameter binding through the RequestParam
annotation. Also supports the ModelAttribute annotation for exposing
model attribute values to the view, as well as InitBinder for binder
initialization methods and SessionAttributes for automatic session
management of specific attributes.
This adapter can be customized through various bean properties. A common use
case is to apply shared binder initialization logic through a custom
WebBindingInitializer.
setPathMatcher(org.springframework.util.PathMatcher),
setMethodNameResolver(org.springframework.web.servlet.mvc.multiaction.MethodNameResolver),
setWebBindingInitializer(org.springframework.web.bind.support.WebBindingInitializer),
setSessionAttributeStore(org.springframework.web.bind.support.SessionAttributeStore)| Modifier and Type | Field and Description |
|---|---|
static String |
PAGE_NOT_FOUND_LOG_CATEGORY
Log category to use when no mapped handler is found for a request.
|
protected static org.apache.commons.logging.Log |
pageNotFoundLogger
Additional logger to use when no mapped handler is found for a request.
|
| Constructor and Description |
|---|
AnnotationMethodHandlerAdapter() |
| Modifier and Type | Method and Description |
|---|---|
protected org.springframework.web.bind.ServletRequestDataBinder |
createBinder(javax.servlet.http.HttpServletRequest request,
Object target,
String objectName)
Template method for creating a new ServletRequestDataBinder instance.
|
long |
getLastModified(javax.servlet.http.HttpServletRequest request,
Object handler) |
List<String> |
getMediaTypeOrder() |
org.springframework.http.converter.HttpMessageConverter<?>[] |
getMessageConverters()
Return the message body converters that this adapter has been configured
with.
|
int |
getOrder() |
org.springframework.web.servlet.ModelAndView |
handle(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
Object handler) |
protected org.springframework.web.servlet.ModelAndView |
invokeHandlerMethod(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
Object handler) |
void |
setAlwaysUseFullPath(boolean alwaysUseFullPath)
Set if URL lookup should always use the full path within the current
servlet context.
|
void |
setBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory) |
void |
setCacheSecondsForSessionAttributeHandlers(int cacheSecondsForSessionAttributeHandlers)
Cache content produced by
@SessionAttributes annotated
handlers for the given number of seconds. |
void |
setCustomArgumentResolver(org.springframework.web.bind.support.WebArgumentResolver argumentResolver)
Set a custom WebArgumentResolvers to use for special method parameter
types.
|
void |
setCustomArgumentResolvers(org.springframework.web.bind.support.WebArgumentResolver[] argumentResolvers)
Set one or more custom WebArgumentResolvers to use for special method
parameter types.
|
void |
setCustomModelAndViewResolver(org.springframework.web.servlet.mvc.annotation.ModelAndViewResolver customModelAndViewResolver)
Set a custom ModelAndViewResolvers to use for special method return types.
|
void |
setCustomModelAndViewResolvers(org.springframework.web.servlet.mvc.annotation.ModelAndViewResolver[] customModelAndViewResolvers)
Set one or more custom ModelAndViewResolvers to use for special method
return types.
|
void |
setDefaultMediaType(org.springframework.http.MediaType defaultContentType)
Sets the default content type.
|
void |
setMediaTypeOrder(List<String> mediaTypeOrder) |
void |
setMediaTypes(Map<String,String> mediaTypes)
Sets the mapping from file extensions to media types.
|
void |
setMessageConverters(org.springframework.http.converter.HttpMessageConverter<?>[] messageConverters)
Set the message body converters to use.
|
void |
setMethodNameResolver(org.springframework.web.servlet.mvc.multiaction.MethodNameResolver methodNameResolver)
Set the MethodNameResolver to use for resolving default handler methods
(carrying an empty
@RequestMapping annotation). |
void |
setOrder(int order)
Specify the order value for this HandlerAdapter bean.
|
void |
setParameterName(String parameterName)
Sets the parameter name that can be used to determine the requested media
type if the
#setFavorParameter(boolean) property is true. |
void |
setParameterNameDiscoverer(org.springframework.core.ParameterNameDiscoverer parameterNameDiscoverer)
Set the ParameterNameDiscoverer to use for resolving method parameter names
if needed (e.g.
|
void |
setPathMatcher(org.springframework.util.PathMatcher pathMatcher)
Set the PathMatcher implementation to use for matching URL paths against
registered URL patterns.
|
void |
setSessionAttributeStore(org.springframework.web.bind.support.SessionAttributeStore sessionAttributeStore)
Specify the strategy to store session attributes with.
|
void |
setSynchronizeOnSession(boolean synchronizeOnSession)
Set if controller execution should be synchronized on the session, to
serialize parallel invocations from the same client.
|
void |
setUrlDecode(boolean urlDecode)
Set if context path and request URI should be URL-decoded.
|
void |
setUrlPathHelper(org.springframework.web.util.UrlPathHelper urlPathHelper)
Set the UrlPathHelper to use for resolution of lookup paths.
|
void |
setWebBindingInitializer(org.springframework.web.bind.support.WebBindingInitializer webBindingInitializer)
Specify a WebBindingInitializer which will apply pre-configured
configuration to every DataBinder that this controller uses.
|
boolean |
supports(Object handler) |
applyCacheSeconds, applyCacheSeconds, cacheForSeconds, cacheForSeconds, checkAndPrepare, checkAndPrepare, getCacheSeconds, getSupportedMethods, isAlwaysMustRevalidate, isRequireSession, isUseCacheControlHeader, isUseCacheControlNoStore, isUseExpiresHeader, preventCaching, setAlwaysMustRevalidate, setCacheSeconds, setRequireSession, setSupportedMethods, setUseCacheControlHeader, setUseCacheControlNoStore, setUseExpiresHeadergetServletContext, getTempDir, getWebApplicationContext, initApplicationContext, initServletContext, isContextRequired, setServletContextpublic static final String PAGE_NOT_FOUND_LOG_CATEGORY
pageNotFoundLogger,
Constant Field Valuesprotected static final org.apache.commons.logging.Log pageNotFoundLogger
PAGE_NOT_FOUND_LOG_CATEGORYprotected org.springframework.web.bind.ServletRequestDataBinder createBinder(javax.servlet.http.HttpServletRequest request,
Object target,
String objectName)
throws Exception
The default implementation creates a standard ServletRequestDataBinder. This can be overridden for custom ServletRequestDataBinder subclasses.
request - current HTTP requesttarget - the target object to bind onto (or null if the
binder is just used to convert a plain parameter value)objectName - the objectName of the target objectException - in case of invalid state or argumentsServletRequestDataBinder.bind(javax.servlet.ServletRequest),
DataBinder.convertIfNecessary(Object, Class,
MethodParameter)public long getLastModified(javax.servlet.http.HttpServletRequest request,
Object handler)
getLastModified in interface org.springframework.web.servlet.HandlerAdapterpublic org.springframework.http.converter.HttpMessageConverter<?>[] getMessageConverters()
public int getOrder()
getOrder in interface org.springframework.core.Orderedpublic org.springframework.web.servlet.ModelAndView handle(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
Object handler)
throws Exception
handle in interface org.springframework.web.servlet.HandlerAdapterExceptionprotected org.springframework.web.servlet.ModelAndView invokeHandlerMethod(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
Object handler)
throws Exception
Exceptionpublic void setAlwaysUseFullPath(boolean alwaysUseFullPath)
Default is "false".
UrlPathHelper.setAlwaysUseFullPath(boolean)public void setBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory)
setBeanFactory in interface org.springframework.beans.factory.BeanFactoryAwarepublic void setCacheSecondsForSessionAttributeHandlers(int cacheSecondsForSessionAttributeHandlers)
@SessionAttributes annotated
handlers for the given number of seconds. Default is 0, preventing caching
completely.
In contrast to the "cacheSeconds" property which will apply to all general
handlers (but not to @SessionAttributes annotated handlers),
this setting will apply to @SessionAttributes annotated
handlers only.
WebContentGenerator.setCacheSeconds(int),
SessionAttributespublic void setCustomArgumentResolver(org.springframework.web.bind.support.WebArgumentResolver argumentResolver)
Such a custom WebArgumentResolver will kick in first, having a chance to resolve an argument value before the standard argument handling kicks in.
public void setCustomArgumentResolvers(org.springframework.web.bind.support.WebArgumentResolver[] argumentResolvers)
Any such custom WebArgumentResolver will kick in first, having a chance to resolve an argument value before the standard argument handling kicks in.
public void setCustomModelAndViewResolver(org.springframework.web.servlet.mvc.annotation.ModelAndViewResolver customModelAndViewResolver)
Such a custom ModelAndViewResolver will kick in first, having a chance to resolve a return value before the standard ModelAndView handling kicks in.
public void setCustomModelAndViewResolvers(org.springframework.web.servlet.mvc.annotation.ModelAndViewResolver[] customModelAndViewResolvers)
Any such custom ModelAndViewResolver will kick in first, having a chance to resolve a return value before the standard ModelAndView handling kicks in.
public void setDefaultMediaType(org.springframework.http.MediaType defaultContentType)
This content type will be used when file extension, parameter, nor
Accept header define a content-type, either through being disabled
or empty.
public void setMediaTypes(Map<String,String> mediaTypes)
public void setMessageConverters(org.springframework.http.converter.HttpMessageConverter<?>[] messageConverters)
These converters are used to convert from and to HTTP requests and responses.
public void setMethodNameResolver(org.springframework.web.servlet.mvc.multiaction.MethodNameResolver methodNameResolver)
@RequestMapping annotation).
Will only kick in when the handler method cannot be resolved uniquely through the annotation metadata already.
public void setOrder(int order)
Default value is Integer.MAX_VALUE, meaning that it's
non-ordered.
Ordered.getOrder()public void setParameterName(String parameterName)
#setFavorParameter(boolean) property is true.
The default parameter name is format.public void setParameterNameDiscoverer(org.springframework.core.ParameterNameDiscoverer parameterNameDiscoverer)
Default is a
LocalVariableTableParameterNameDiscoverer.
public void setPathMatcher(org.springframework.util.PathMatcher pathMatcher)
Default is AntPathMatcher.
public void setSessionAttributeStore(org.springframework.web.bind.support.SessionAttributeStore sessionAttributeStore)
Default is
DefaultSessionAttributeStore,
storing session attributes in the HttpSession, using the same attribute
name as in the model.
public void setSynchronizeOnSession(boolean synchronizeOnSession)
More specifically, the execution of the handleRequestInternal
method 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_ATTRIBUTE constant. 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.
HttpSessionMutexListener,
WebUtils.getSessionMutex(javax.servlet.http.HttpSession)public void setUrlDecode(boolean urlDecode)
Uses either the request encoding or the default encoding according to the Servlet spec (ISO-8859-1).
UrlPathHelper.setUrlDecode(boolean)public void setUrlPathHelper(org.springframework.web.util.UrlPathHelper urlPathHelper)
Use this to override the default UrlPathHelper with a custom subclass, or to share common UrlPathHelper settings across multiple HandlerMappings and HandlerAdapters.
public void setWebBindingInitializer(org.springframework.web.bind.support.WebBindingInitializer webBindingInitializer)
public boolean supports(Object handler)
supports in interface org.springframework.web.servlet.HandlerAdapterCopyright © 2015 Revolution Systems Inc.. All rights reserved.