Skip to content

Commit e4a13cd

Browse files
committed
Polish (minor) RequestMappingHandlerAdapter
Revise order of fields reflecting configurable vs internal fields and also grouping them accordingly.
1 parent f036ed6 commit e4a13cd

File tree

1 file changed

+68
-67
lines changed

1 file changed

+68
-67
lines changed

spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerAdapter.java

Lines changed: 68 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@
6464
import org.springframework.web.context.request.WebRequest;
6565
import org.springframework.web.context.request.async.AsyncTask;
6666
import org.springframework.web.context.request.async.AsyncWebRequest;
67-
import org.springframework.web.context.request.async.WebAsyncUtils;
6867
import org.springframework.web.context.request.async.WebAsyncManager;
68+
import org.springframework.web.context.request.async.WebAsyncUtils;
6969
import org.springframework.web.method.ControllerAdviceBean;
7070
import org.springframework.web.method.HandlerMethod;
7171
import org.springframework.web.method.HandlerMethodSelector;
@@ -115,35 +115,42 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter i
115115

116116
private List<HandlerMethodArgumentResolver> customArgumentResolvers;
117117

118+
private HandlerMethodArgumentResolverComposite argumentResolvers;
119+
120+
private HandlerMethodArgumentResolverComposite initBinderArgumentResolvers;
121+
118122
private List<HandlerMethodReturnValueHandler> customReturnValueHandlers;
119123

124+
private HandlerMethodReturnValueHandlerComposite returnValueHandlers;
125+
120126
private List<ModelAndViewResolver> modelAndViewResolvers;
121127

128+
private ContentNegotiationManager contentNegotiationManager = new ContentNegotiationManager();
129+
122130
private List<HttpMessageConverter<?>> messageConverters;
123131

124132
private WebBindingInitializer webBindingInitializer;
125133

134+
private AsyncTaskExecutor taskExecutor = new SimpleAsyncTaskExecutor("MvcAsync");
135+
136+
private Long asyncRequestTimeout;
137+
138+
private boolean ignoreDefaultModelOnRedirect = false;
139+
126140
private int cacheSecondsForSessionAttributeHandlers = 0;
127141

128142
private boolean synchronizeOnSession = false;
129143

144+
private SessionAttributeStore sessionAttributeStore = new DefaultSessionAttributeStore();
145+
130146
private ParameterNameDiscoverer parameterNameDiscoverer = new LocalVariableTableParameterNameDiscoverer();
131147

132148
private ConfigurableBeanFactory beanFactory;
133149

134-
private SessionAttributeStore sessionAttributeStore = new DefaultSessionAttributeStore();
135-
136-
private boolean ignoreDefaultModelOnRedirect = false;
137150

138151
private final Map<Class<?>, SessionAttributesHandler> sessionAttributesHandlerCache =
139152
new ConcurrentHashMap<Class<?>, SessionAttributesHandler>();
140153

141-
private HandlerMethodArgumentResolverComposite argumentResolvers;
142-
143-
private HandlerMethodArgumentResolverComposite initBinderArgumentResolvers;
144-
145-
private HandlerMethodReturnValueHandlerComposite returnValueHandlers;
146-
147154
private final Map<Class<?>, Set<Method>> initBinderCache = new ConcurrentHashMap<Class<?>, Set<Method>>();
148155

149156
private final Map<ControllerAdviceBean, Set<Method>> initBinderAdviceCache =
@@ -154,12 +161,6 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter i
154161
private final Map<ControllerAdviceBean, Set<Method>> modelAttributeAdviceCache =
155162
new LinkedHashMap<ControllerAdviceBean, Set<Method>>();
156163

157-
private AsyncTaskExecutor taskExecutor = new SimpleAsyncTaskExecutor("MvcAsync");
158-
159-
private Long asyncRequestTimeout;
160-
161-
private ContentNegotiationManager contentNegotiationManager = new ContentNegotiationManager();
162-
163164

164165
/**
165166
* Default constructor.
@@ -307,6 +308,14 @@ public void setMessageConverters(List<HttpMessageConverter<?>> messageConverters
307308
this.messageConverters = messageConverters;
308309
}
309310

311+
/**
312+
* Set the {@link ContentNegotiationManager} to use to determine requested media types.
313+
* If not set, the default constructor is used.
314+
*/
315+
public void setContentNegotiationManager(ContentNegotiationManager contentNegotiationManager) {
316+
this.contentNegotiationManager = contentNegotiationManager;
317+
}
318+
310319
/**
311320
* Return the configured message body converters.
312321
*/
@@ -329,6 +338,49 @@ public WebBindingInitializer getWebBindingInitializer() {
329338
return webBindingInitializer;
330339
}
331340

341+
/**
342+
* Set the default {@link AsyncTaskExecutor} to use when a controller method
343+
* return a {@link Callable}. Controller methods can override this default on
344+
* a per-request basis by returning an {@link AsyncTask}.
345+
* <p>By default a {@link SimpleAsyncTaskExecutor} instance is used.
346+
* It's recommended to change that default in production as the simple executor
347+
* does not re-use threads.
348+
*/
349+
public void setTaskExecutor(AsyncTaskExecutor taskExecutor) {
350+
this.taskExecutor = taskExecutor;
351+
}
352+
353+
/**
354+
* Specify the amount of time, in milliseconds, before concurrent handling
355+
* should time out. In Servlet 3, the timeout begins after the main request
356+
* processing thread has exited and ends when the request is dispatched again
357+
* for further processing of the concurrently produced result.
358+
* <p>If this value is not set, the default timeout of the underlying
359+
* implementation is used, e.g. 10 seconds on Tomcat with Servlet 3.
360+
* @param timeout the timeout value in milliseconds
361+
*/
362+
public void setAsyncRequestTimeout(long timeout) {
363+
this.asyncRequestTimeout = timeout;
364+
}
365+
366+
/**
367+
* By default the content of the "default" model is used both during
368+
* rendering and redirect scenarios. Alternatively a controller method
369+
* can declare a {@link RedirectAttributes} argument and use it to provide
370+
* attributes for a redirect.
371+
* <p>Setting this flag to {@code true} guarantees the "default" model is
372+
* never used in a redirect scenario even if a RedirectAttributes argument
373+
* is not declared. Setting it to {@code false} means the "default" model
374+
* may be used in a redirect if the controller method doesn't declare a
375+
* RedirectAttributes argument.
376+
* <p>The default setting is {@code false} but new applications should
377+
* consider setting it to {@code true}.
378+
* @see RedirectAttributes
379+
*/
380+
public void setIgnoreDefaultModelOnRedirect(boolean ignoreDefaultModelOnRedirect) {
381+
this.ignoreDefaultModelOnRedirect = ignoreDefaultModelOnRedirect;
382+
}
383+
332384
/**
333385
* Specify the strategy to store session attributes with. The default is
334386
* {@link org.springframework.web.bind.support.DefaultSessionAttributeStore},
@@ -383,57 +435,6 @@ public void setParameterNameDiscoverer(ParameterNameDiscoverer parameterNameDisc
383435
this.parameterNameDiscoverer = parameterNameDiscoverer;
384436
}
385437

386-
/**
387-
* By default the content of the "default" model is used both during
388-
* rendering and redirect scenarios. Alternatively a controller method
389-
* can declare a {@link RedirectAttributes} argument and use it to provide
390-
* attributes for a redirect.
391-
* <p>Setting this flag to {@code true} guarantees the "default" model is
392-
* never used in a redirect scenario even if a RedirectAttributes argument
393-
* is not declared. Setting it to {@code false} means the "default" model
394-
* may be used in a redirect if the controller method doesn't declare a
395-
* RedirectAttributes argument.
396-
* <p>The default setting is {@code false} but new applications should
397-
* consider setting it to {@code true}.
398-
* @see RedirectAttributes
399-
*/
400-
public void setIgnoreDefaultModelOnRedirect(boolean ignoreDefaultModelOnRedirect) {
401-
this.ignoreDefaultModelOnRedirect = ignoreDefaultModelOnRedirect;
402-
}
403-
404-
/**
405-
* Set the default {@link AsyncTaskExecutor} to use when a controller method
406-
* return a {@link Callable}. Controller methods can override this default on
407-
* a per-request basis by returning an {@link AsyncTask}.
408-
* <p>By default a {@link SimpleAsyncTaskExecutor} instance is used.
409-
* It's recommended to change that default in production as the simple executor
410-
* does not re-use threads.
411-
*/
412-
public void setTaskExecutor(AsyncTaskExecutor taskExecutor) {
413-
this.taskExecutor = taskExecutor;
414-
}
415-
416-
/**
417-
* Specify the amount of time, in milliseconds, before concurrent handling
418-
* should time out. In Servlet 3, the timeout begins after the main request
419-
* processing thread has exited and ends when the request is dispatched again
420-
* for further processing of the concurrently produced result.
421-
* <p>If this value is not set, the default timeout of the underlying
422-
* implementation is used, e.g. 10 seconds on Tomcat with Servlet 3.
423-
* @param timeout the timeout value in milliseconds
424-
*/
425-
public void setAsyncRequestTimeout(long timeout) {
426-
this.asyncRequestTimeout = timeout;
427-
}
428-
429-
/**
430-
* Set the {@link ContentNegotiationManager} to use to determine requested media types.
431-
* If not set, the default constructor is used.
432-
*/
433-
public void setContentNegotiationManager(ContentNegotiationManager contentNegotiationManager) {
434-
this.contentNegotiationManager = contentNegotiationManager;
435-
}
436-
437438
/**
438439
* {@inheritDoc}
439440
* <p>A {@link ConfigurableBeanFactory} is expected for resolving

0 commit comments

Comments
 (0)