diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerAdapter.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerAdapter.java index da50107b0b..197bf6f5ab 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerAdapter.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerAdapter.java @@ -64,8 +64,8 @@ import org.springframework.web.context.request.ServletWebRequest; import org.springframework.web.context.request.WebRequest; import org.springframework.web.context.request.async.AsyncTask; import org.springframework.web.context.request.async.AsyncWebRequest; -import org.springframework.web.context.request.async.WebAsyncUtils; import org.springframework.web.context.request.async.WebAsyncManager; +import org.springframework.web.context.request.async.WebAsyncUtils; import org.springframework.web.method.ControllerAdviceBean; import org.springframework.web.method.HandlerMethod; import org.springframework.web.method.HandlerMethodSelector; @@ -115,35 +115,42 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter i private List customArgumentResolvers; + private HandlerMethodArgumentResolverComposite argumentResolvers; + + private HandlerMethodArgumentResolverComposite initBinderArgumentResolvers; + private List customReturnValueHandlers; + private HandlerMethodReturnValueHandlerComposite returnValueHandlers; + private List modelAndViewResolvers; + private ContentNegotiationManager contentNegotiationManager = new ContentNegotiationManager(); + private List> messageConverters; private WebBindingInitializer webBindingInitializer; + private AsyncTaskExecutor taskExecutor = new SimpleAsyncTaskExecutor("MvcAsync"); + + private Long asyncRequestTimeout; + + private boolean ignoreDefaultModelOnRedirect = false; + private int cacheSecondsForSessionAttributeHandlers = 0; private boolean synchronizeOnSession = false; + private SessionAttributeStore sessionAttributeStore = new DefaultSessionAttributeStore(); + private ParameterNameDiscoverer parameterNameDiscoverer = new LocalVariableTableParameterNameDiscoverer(); private ConfigurableBeanFactory beanFactory; - private SessionAttributeStore sessionAttributeStore = new DefaultSessionAttributeStore(); - - private boolean ignoreDefaultModelOnRedirect = false; private final Map, SessionAttributesHandler> sessionAttributesHandlerCache = new ConcurrentHashMap, SessionAttributesHandler>(); - private HandlerMethodArgumentResolverComposite argumentResolvers; - - private HandlerMethodArgumentResolverComposite initBinderArgumentResolvers; - - private HandlerMethodReturnValueHandlerComposite returnValueHandlers; - private final Map, Set> initBinderCache = new ConcurrentHashMap, Set>(); private final Map> initBinderAdviceCache = @@ -154,12 +161,6 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter i private final Map> modelAttributeAdviceCache = new LinkedHashMap>(); - private AsyncTaskExecutor taskExecutor = new SimpleAsyncTaskExecutor("MvcAsync"); - - private Long asyncRequestTimeout; - - private ContentNegotiationManager contentNegotiationManager = new ContentNegotiationManager(); - /** * Default constructor. @@ -307,6 +308,14 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter i this.messageConverters = messageConverters; } + /** + * Set the {@link ContentNegotiationManager} to use to determine requested media types. + * If not set, the default constructor is used. + */ + public void setContentNegotiationManager(ContentNegotiationManager contentNegotiationManager) { + this.contentNegotiationManager = contentNegotiationManager; + } + /** * Return the configured message body converters. */ @@ -329,6 +338,49 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter i return webBindingInitializer; } + /** + * Set the default {@link AsyncTaskExecutor} to use when a controller method + * return a {@link Callable}. Controller methods can override this default on + * a per-request basis by returning an {@link AsyncTask}. + *

By default a {@link SimpleAsyncTaskExecutor} instance is used. + * It's recommended to change that default in production as the simple executor + * does not re-use threads. + */ + public void setTaskExecutor(AsyncTaskExecutor taskExecutor) { + this.taskExecutor = taskExecutor; + } + + /** + * 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, e.g. 10 seconds on Tomcat with Servlet 3. + * @param timeout the timeout value in milliseconds + */ + public void setAsyncRequestTimeout(long timeout) { + this.asyncRequestTimeout = timeout; + } + + /** + * By default the content of the "default" model is used both during + * rendering and redirect scenarios. Alternatively a controller method + * can declare a {@link RedirectAttributes} argument and use it to provide + * attributes for a redirect. + *

Setting this flag to {@code true} guarantees the "default" model is + * never used in a redirect scenario even if a RedirectAttributes argument + * is not declared. Setting it to {@code false} means the "default" model + * may be used in a redirect if the controller method doesn't declare a + * RedirectAttributes argument. + *

The default setting is {@code false} but new applications should + * consider setting it to {@code true}. + * @see RedirectAttributes + */ + public void setIgnoreDefaultModelOnRedirect(boolean ignoreDefaultModelOnRedirect) { + this.ignoreDefaultModelOnRedirect = ignoreDefaultModelOnRedirect; + } + /** * Specify the strategy to store session attributes with. The default is * {@link org.springframework.web.bind.support.DefaultSessionAttributeStore}, @@ -383,57 +435,6 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter i this.parameterNameDiscoverer = parameterNameDiscoverer; } - /** - * By default the content of the "default" model is used both during - * rendering and redirect scenarios. Alternatively a controller method - * can declare a {@link RedirectAttributes} argument and use it to provide - * attributes for a redirect. - *

Setting this flag to {@code true} guarantees the "default" model is - * never used in a redirect scenario even if a RedirectAttributes argument - * is not declared. Setting it to {@code false} means the "default" model - * may be used in a redirect if the controller method doesn't declare a - * RedirectAttributes argument. - *

The default setting is {@code false} but new applications should - * consider setting it to {@code true}. - * @see RedirectAttributes - */ - public void setIgnoreDefaultModelOnRedirect(boolean ignoreDefaultModelOnRedirect) { - this.ignoreDefaultModelOnRedirect = ignoreDefaultModelOnRedirect; - } - - /** - * Set the default {@link AsyncTaskExecutor} to use when a controller method - * return a {@link Callable}. Controller methods can override this default on - * a per-request basis by returning an {@link AsyncTask}. - *

By default a {@link SimpleAsyncTaskExecutor} instance is used. - * It's recommended to change that default in production as the simple executor - * does not re-use threads. - */ - public void setTaskExecutor(AsyncTaskExecutor taskExecutor) { - this.taskExecutor = taskExecutor; - } - - /** - * 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, e.g. 10 seconds on Tomcat with Servlet 3. - * @param timeout the timeout value in milliseconds - */ - public void setAsyncRequestTimeout(long timeout) { - this.asyncRequestTimeout = timeout; - } - - /** - * Set the {@link ContentNegotiationManager} to use to determine requested media types. - * If not set, the default constructor is used. - */ - public void setContentNegotiationManager(ContentNegotiationManager contentNegotiationManager) { - this.contentNegotiationManager = contentNegotiationManager; - } - /** * {@inheritDoc} *

A {@link ConfigurableBeanFactory} is expected for resolving