17
17
package org .springframework .web .servlet .config .annotation ;
18
18
19
19
import java .util .ArrayList ;
20
+ import java .util .Collections ;
20
21
import java .util .HashMap ;
21
22
import java .util .List ;
22
23
import java .util .Locale ;
@@ -233,6 +234,7 @@ public ServletContext getServletContext() {
233
234
return this .servletContext ;
234
235
}
235
236
237
+
236
238
/**
237
239
* Return a {@link RequestMappingHandlerMapping} ordered at 0 for mapping
238
240
* requests to annotated controllers.
@@ -255,11 +257,13 @@ public RequestMappingHandlerMapping requestMappingHandlerMapping() {
255
257
if (configurer .isUseTrailingSlashMatch () != null ) {
256
258
handlerMapping .setUseTrailingSlashMatch (configurer .isUseTrailingSlashMatch ());
257
259
}
258
- if (configurer .getPathMatcher () != null ) {
259
- handlerMapping .setPathMatcher (configurer .getPathMatcher ());
260
+ UrlPathHelper pathHelper = configurer .getUrlPathHelper ();
261
+ if (pathHelper != null ) {
262
+ handlerMapping .setUrlPathHelper (pathHelper );
260
263
}
261
- if (configurer .getUrlPathHelper () != null ) {
262
- handlerMapping .setUrlPathHelper (configurer .getUrlPathHelper ());
264
+ PathMatcher pathMatcher = configurer .getPathMatcher ();
265
+ if (pathMatcher != null ) {
266
+ handlerMapping .setPathMatcher (pathMatcher );
263
267
}
264
268
265
269
return handlerMapping ;
@@ -339,7 +343,7 @@ public ContentNegotiationManager mvcContentNegotiationManager() {
339
343
}
340
344
341
345
protected Map <String , MediaType > getDefaultMediaTypes () {
342
- Map <String , MediaType > map = new HashMap <String , MediaType >();
346
+ Map <String , MediaType > map = new HashMap <String , MediaType >(4 );
343
347
if (romePresent ) {
344
348
map .put ("atom" , MediaType .APPLICATION_ATOM_XML );
345
349
map .put ("rss" , MediaType .valueOf ("application/rss+xml" ));
@@ -487,18 +491,14 @@ public RequestMappingHandlerAdapter requestMappingHandlerAdapter() {
487
491
adapter .setCustomReturnValueHandlers (getReturnValueHandlers ());
488
492
489
493
if (jackson2Present ) {
490
- List <RequestBodyAdvice > requestBodyAdvices = new ArrayList <RequestBodyAdvice >();
491
- requestBodyAdvices .add (new JsonViewRequestBodyAdvice ());
492
- adapter .setRequestBodyAdvice (requestBodyAdvices );
493
-
494
- List <ResponseBodyAdvice <?>> responseBodyAdvices = new ArrayList <ResponseBodyAdvice <?>>();
495
- responseBodyAdvices .add (new JsonViewResponseBodyAdvice ());
496
- adapter .setResponseBodyAdvice (responseBodyAdvices );
494
+ adapter .setRequestBodyAdvice (
495
+ Collections .<RequestBodyAdvice >singletonList (new JsonViewRequestBodyAdvice ()));
496
+ adapter .setResponseBodyAdvice (
497
+ Collections .<ResponseBodyAdvice <?>>singletonList (new JsonViewResponseBodyAdvice ()));
497
498
}
498
499
499
500
AsyncSupportConfigurer configurer = new AsyncSupportConfigurer ();
500
501
configureAsyncSupport (configurer );
501
-
502
502
if (configurer .getTaskExecutor () != null ) {
503
503
adapter .setTaskExecutor (configurer .getTaskExecutor ());
504
504
}
@@ -531,6 +531,13 @@ protected ConfigurableWebBindingInitializer getConfigurableWebBindingInitializer
531
531
return initializer ;
532
532
}
533
533
534
+ /**
535
+ * Override this method to provide a custom {@link MessageCodesResolver}.
536
+ */
537
+ protected MessageCodesResolver getMessageCodesResolver () {
538
+ return null ;
539
+ }
540
+
534
541
/**
535
542
* Override this method to configure asynchronous request processing options.
536
543
* @see AsyncSupportConfigurer
@@ -580,7 +587,7 @@ public Validator mvcValidator() {
580
587
catch (LinkageError ex ) {
581
588
throw new BeanInitializationException ("Could not load default validator class" , ex );
582
589
}
583
- validator = (Validator ) BeanUtils .instantiate (clazz );
590
+ validator = (Validator ) BeanUtils .instantiateClass (clazz );
584
591
}
585
592
else {
586
593
validator = new NoOpValidator ();
@@ -589,6 +596,13 @@ public Validator mvcValidator() {
589
596
return validator ;
590
597
}
591
598
599
+ /**
600
+ * Override this method to provide a custom {@link Validator}.
601
+ */
602
+ protected Validator getValidator () {
603
+ return null ;
604
+ }
605
+
592
606
/**
593
607
* Return a global {@link PathMatcher} instance for path matching
594
608
* patterns in {@link HandlerMapping}s.
@@ -615,26 +629,8 @@ public PathMatcher mvcPathMatcher() {
615
629
*/
616
630
@ Bean
617
631
public UrlPathHelper mvcUrlPathHelper () {
618
- if (getPathMatchConfigurer ().getUrlPathHelper () != null ) {
619
- return getPathMatchConfigurer ().getUrlPathHelper ();
620
- }
621
- else {
622
- return new UrlPathHelper ();
623
- }
624
- }
625
-
626
- /**
627
- * Override this method to provide a custom {@link Validator}.
628
- */
629
- protected Validator getValidator () {
630
- return null ;
631
- }
632
-
633
- /**
634
- * Override this method to provide a custom {@link MessageCodesResolver}.
635
- */
636
- protected MessageCodesResolver getMessageCodesResolver () {
637
- return null ;
632
+ UrlPathHelper pathHelper = getPathMatchConfigurer ().getUrlPathHelper ();
633
+ return (pathHelper != null ? pathHelper : new UrlPathHelper ());
638
634
}
639
635
640
636
/**
@@ -817,11 +813,9 @@ public SimpleControllerHandlerAdapter simpleControllerHandlerAdapter() {
817
813
public HandlerExceptionResolver handlerExceptionResolver () {
818
814
List <HandlerExceptionResolver > exceptionResolvers = new ArrayList <HandlerExceptionResolver >();
819
815
configureHandlerExceptionResolvers (exceptionResolvers );
820
-
821
816
if (exceptionResolvers .isEmpty ()) {
822
817
addDefaultHandlerExceptionResolvers (exceptionResolvers );
823
818
}
824
-
825
819
extendHandlerExceptionResolvers (exceptionResolvers );
826
820
HandlerExceptionResolverComposite composite = new HandlerExceptionResolverComposite ();
827
821
composite .setOrder (0 );
@@ -871,9 +865,8 @@ protected final void addDefaultHandlerExceptionResolvers(List<HandlerExceptionRe
871
865
exceptionHandlerResolver .setCustomArgumentResolvers (getArgumentResolvers ());
872
866
exceptionHandlerResolver .setCustomReturnValueHandlers (getReturnValueHandlers ());
873
867
if (jackson2Present ) {
874
- List <ResponseBodyAdvice <?>> interceptors = new ArrayList <ResponseBodyAdvice <?>>();
875
- interceptors .add (new JsonViewResponseBodyAdvice ());
876
- exceptionHandlerResolver .setResponseBodyAdvice (interceptors );
868
+ exceptionHandlerResolver .setResponseBodyAdvice (
869
+ Collections .<ResponseBodyAdvice <?>>singletonList (new JsonViewResponseBodyAdvice ()));
877
870
}
878
871
exceptionHandlerResolver .setApplicationContext (this .applicationContext );
879
872
exceptionHandlerResolver .afterPropertiesSet ();
0 commit comments