@@ -164,10 +164,10 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv
164
164
165
165
private List <Object > interceptors ;
166
166
167
- private ContentNegotiationManager contentNegotiationManager ;
168
-
169
167
private PathMatchConfigurer pathMatchConfigurer ;
170
168
169
+ private ContentNegotiationManager contentNegotiationManager ;
170
+
171
171
private List <HttpMessageConverter <?>> messageConverters ;
172
172
173
173
@@ -186,6 +186,7 @@ public void setServletContext(ServletContext servletContext) {
186
186
this .servletContext = servletContext ;
187
187
}
188
188
189
+
189
190
/**
190
191
* Return a {@link RequestMappingHandlerMapping} ordered at 0 for mapping
191
192
* requests to annotated controllers.
@@ -207,11 +208,13 @@ public RequestMappingHandlerMapping requestMappingHandlerMapping() {
207
208
if (configurer .isUseTrailingSlashMatch () != null ) {
208
209
handlerMapping .setUseTrailingSlashMatch (configurer .isUseTrailingSlashMatch ());
209
210
}
210
- if (configurer .getPathMatcher () != null ) {
211
- handlerMapping .setPathMatcher (configurer .getPathMatcher ());
211
+ UrlPathHelper pathHelper = configurer .getUrlPathHelper ();
212
+ if (pathHelper != null ) {
213
+ handlerMapping .setUrlPathHelper (pathHelper );
212
214
}
213
- if (configurer .getUrlPathHelper () != null ) {
214
- handlerMapping .setUrlPathHelper (configurer .getUrlPathHelper ());
215
+ PathMatcher pathMatcher = configurer .getPathMatcher ();
216
+ if (pathMatcher != null ) {
217
+ handlerMapping .setPathMatcher (pathMatcher );
215
218
}
216
219
217
220
return handlerMapping ;
@@ -240,48 +243,6 @@ protected final Object[] getInterceptors() {
240
243
protected void addInterceptors (InterceptorRegistry registry ) {
241
244
}
242
245
243
- /**
244
- * Return a {@link ContentNegotiationManager} instance to use to determine
245
- * requested {@linkplain MediaType media types} in a given request.
246
- */
247
- @ Bean
248
- public ContentNegotiationManager mvcContentNegotiationManager () {
249
- if (this .contentNegotiationManager == null ) {
250
- ContentNegotiationConfigurer configurer = new ContentNegotiationConfigurer (this .servletContext );
251
- configurer .mediaTypes (getDefaultMediaTypes ());
252
- configureContentNegotiation (configurer );
253
- try {
254
- this .contentNegotiationManager = configurer .getContentNegotiationManager ();
255
- }
256
- catch (Exception ex ) {
257
- throw new BeanInitializationException ("Could not create ContentNegotiationManager" , ex );
258
- }
259
- }
260
- return this .contentNegotiationManager ;
261
- }
262
-
263
- protected Map <String , MediaType > getDefaultMediaTypes () {
264
- Map <String , MediaType > map = new HashMap <String , MediaType >();
265
- if (romePresent ) {
266
- map .put ("atom" , MediaType .APPLICATION_ATOM_XML );
267
- map .put ("rss" , MediaType .valueOf ("application/rss+xml" ));
268
- }
269
- if (jaxb2Present ) {
270
- map .put ("xml" , MediaType .APPLICATION_XML );
271
- }
272
- if (jackson2Present || jacksonPresent ) {
273
- map .put ("json" , MediaType .APPLICATION_JSON );
274
- }
275
- return map ;
276
- }
277
-
278
- /**
279
- * Override this method to configure content negotiation.
280
- * @see DefaultServletHandlerConfigurer
281
- */
282
- protected void configureContentNegotiation (ContentNegotiationConfigurer configurer ) {
283
- }
284
-
285
246
/**
286
247
* Callback for building the {@link PathMatchConfigurer}.
287
248
* Delegates to {@link #configurePathMatch}.
@@ -312,12 +273,8 @@ public void configurePathMatch(PathMatchConfigurer configurer) {
312
273
*/
313
274
@ Bean
314
275
public PathMatcher mvcPathMatcher () {
315
- if (getPathMatchConfigurer ().getPathMatcher () != null ) {
316
- return getPathMatchConfigurer ().getPathMatcher ();
317
- }
318
- else {
319
- return new AntPathMatcher ();
320
- }
276
+ PathMatcher pathMatcher = getPathMatchConfigurer ().getPathMatcher ();
277
+ return (pathMatcher != null ? pathMatcher : new AntPathMatcher ());
321
278
}
322
279
323
280
/**
@@ -329,12 +286,50 @@ public PathMatcher mvcPathMatcher() {
329
286
*/
330
287
@ Bean
331
288
public UrlPathHelper mvcUrlPathHelper () {
332
- if (getPathMatchConfigurer ().getUrlPathHelper () != null ) {
333
- return getPathMatchConfigurer ().getUrlPathHelper ();
289
+ UrlPathHelper pathHelper = getPathMatchConfigurer ().getUrlPathHelper ();
290
+ return (pathHelper != null ? pathHelper : new UrlPathHelper ());
291
+ }
292
+
293
+ /**
294
+ * Return a {@link ContentNegotiationManager} instance to use to determine
295
+ * requested {@linkplain MediaType media types} in a given request.
296
+ */
297
+ @ Bean
298
+ public ContentNegotiationManager mvcContentNegotiationManager () {
299
+ if (this .contentNegotiationManager == null ) {
300
+ ContentNegotiationConfigurer configurer = new ContentNegotiationConfigurer (this .servletContext );
301
+ configurer .mediaTypes (getDefaultMediaTypes ());
302
+ configureContentNegotiation (configurer );
303
+ try {
304
+ this .contentNegotiationManager = configurer .getContentNegotiationManager ();
305
+ }
306
+ catch (Exception ex ) {
307
+ throw new BeanInitializationException ("Could not create ContentNegotiationManager" , ex );
308
+ }
334
309
}
335
- else {
336
- return new UrlPathHelper ();
310
+ return this .contentNegotiationManager ;
311
+ }
312
+
313
+ protected Map <String , MediaType > getDefaultMediaTypes () {
314
+ Map <String , MediaType > map = new HashMap <String , MediaType >(4 );
315
+ if (romePresent ) {
316
+ map .put ("atom" , MediaType .APPLICATION_ATOM_XML );
317
+ map .put ("rss" , MediaType .valueOf ("application/rss+xml" ));
318
+ }
319
+ if (jaxb2Present ) {
320
+ map .put ("xml" , MediaType .APPLICATION_XML );
337
321
}
322
+ if (jackson2Present || jacksonPresent ) {
323
+ map .put ("json" , MediaType .APPLICATION_JSON );
324
+ }
325
+ return map ;
326
+ }
327
+
328
+ /**
329
+ * Override this method to configure content negotiation.
330
+ * @see DefaultServletHandlerConfigurer
331
+ */
332
+ protected void configureContentNegotiation (ContentNegotiationConfigurer configurer ) {
338
333
}
339
334
340
335
/**
@@ -450,7 +445,6 @@ public RequestMappingHandlerAdapter requestMappingHandlerAdapter() {
450
445
451
446
AsyncSupportConfigurer configurer = new AsyncSupportConfigurer ();
452
447
configureAsyncSupport (configurer );
453
-
454
448
if (configurer .getTaskExecutor () != null ) {
455
449
adapter .setTaskExecutor (configurer .getTaskExecutor ());
456
450
}
@@ -475,6 +469,20 @@ protected ConfigurableWebBindingInitializer getConfigurableWebBindingInitializer
475
469
return initializer ;
476
470
}
477
471
472
+ /**
473
+ * Override this method to provide a custom {@link MessageCodesResolver}.
474
+ */
475
+ protected MessageCodesResolver getMessageCodesResolver () {
476
+ return null ;
477
+ }
478
+
479
+ /**
480
+ * Override this method to configure asynchronous request processing options.
481
+ * @see AsyncSupportConfigurer
482
+ */
483
+ protected void configureAsyncSupport (AsyncSupportConfigurer configurer ) {
484
+ }
485
+
478
486
/**
479
487
* Return a {@link FormattingConversionService} for use with annotated
480
488
* controller methods and the {@code spring:eval} JSP tag.
@@ -487,6 +495,12 @@ public FormattingConversionService mvcConversionService() {
487
495
return conversionService ;
488
496
}
489
497
498
+ /**
499
+ * Override this method to add custom {@link Converter}s and {@link Formatter}s.
500
+ */
501
+ protected void addFormatters (FormatterRegistry registry ) {
502
+ }
503
+
490
504
/**
491
505
* Return a global {@link Validator} instance for example for validating
492
506
* {@code @ModelAttribute} and {@code @RequestBody} method arguments.
@@ -511,7 +525,7 @@ public Validator mvcValidator() {
511
525
catch (LinkageError ex ) {
512
526
throw new BeanInitializationException ("Could not load default validator class" , ex );
513
527
}
514
- validator = (Validator ) BeanUtils .instantiate (clazz );
528
+ validator = (Validator ) BeanUtils .instantiateClass (clazz );
515
529
}
516
530
else {
517
531
validator = new NoOpValidator ();
@@ -527,13 +541,6 @@ protected Validator getValidator() {
527
541
return null ;
528
542
}
529
543
530
- /**
531
- * Override this method to provide a custom {@link MessageCodesResolver}.
532
- */
533
- protected MessageCodesResolver getMessageCodesResolver () {
534
- return null ;
535
- }
536
-
537
544
/**
538
545
* Add custom {@link HandlerMethodArgumentResolver}s to use in addition to
539
546
* the ones registered by default.
@@ -625,19 +632,6 @@ else if (jacksonPresent) {
625
632
}
626
633
}
627
634
628
- /**
629
- * Override this method to add custom {@link Converter}s and {@link Formatter}s.
630
- */
631
- protected void addFormatters (FormatterRegistry registry ) {
632
- }
633
-
634
- /**
635
- * Override this method to configure asynchronous request processing options.
636
- * @see AsyncSupportConfigurer
637
- */
638
- public void configureAsyncSupport (AsyncSupportConfigurer configurer ) {
639
- }
640
-
641
635
/**
642
636
* Returns a {@link HttpRequestHandlerAdapter} for processing requests
643
637
* with {@link HttpRequestHandler}s.
@@ -670,11 +664,9 @@ public SimpleControllerHandlerAdapter simpleControllerHandlerAdapter() {
670
664
public HandlerExceptionResolver handlerExceptionResolver () {
671
665
List <HandlerExceptionResolver > exceptionResolvers = new ArrayList <HandlerExceptionResolver >();
672
666
configureHandlerExceptionResolvers (exceptionResolvers );
673
-
674
667
if (exceptionResolvers .isEmpty ()) {
675
668
addDefaultHandlerExceptionResolvers (exceptionResolvers );
676
669
}
677
-
678
670
HandlerExceptionResolverComposite composite = new HandlerExceptionResolverComposite ();
679
671
composite .setOrder (0 );
680
672
composite .setExceptionResolvers (exceptionResolvers );
0 commit comments