|
87 | 87 | *
|
88 | 88 | * <p>This class registers the following {@link HandlerMapping}s:</p>
|
89 | 89 | * <ul>
|
90 |
| - * <li>{@link RequestMappingHandlerMapping} |
91 |
| - * ordered at 0 for mapping requests to annotated controller methods. |
92 |
| - * <li>{@link HandlerMapping} |
93 |
| - * ordered at 1 to map URL paths directly to view names. |
94 |
| - * <li>{@link BeanNameUrlHandlerMapping} |
95 |
| - * ordered at 2 to map URL paths to controller bean names. |
96 |
| - * <li>{@link HandlerMapping} |
97 |
| - * ordered at {@code Integer.MAX_VALUE-1} to serve static resource requests. |
98 |
| - * <li>{@link HandlerMapping} |
99 |
| - * ordered at {@code Integer.MAX_VALUE} to forward requests to the default servlet. |
| 90 | + * <li>{@link RequestMappingHandlerMapping} |
| 91 | + * ordered at 0 for mapping requests to annotated controller methods. |
| 92 | + * <li>{@link HandlerMapping} |
| 93 | + * ordered at 1 to map URL paths directly to view names. |
| 94 | + * <li>{@link BeanNameUrlHandlerMapping} |
| 95 | + * ordered at 2 to map URL paths to controller bean names. |
| 96 | + * <li>{@link HandlerMapping} |
| 97 | + * ordered at {@code Integer.MAX_VALUE-1} to serve static resource requests. |
| 98 | + * <li>{@link HandlerMapping} |
| 99 | + * ordered at {@code Integer.MAX_VALUE} to forward requests to the default servlet. |
100 | 100 | * </ul>
|
101 | 101 | *
|
102 | 102 | * <p>Registers these {@link HandlerAdapter}s:
|
103 | 103 | * <ul>
|
104 |
| - * <li>{@link RequestMappingHandlerAdapter} |
105 |
| - * for processing requests with annotated controller methods. |
106 |
| - * <li>{@link HttpRequestHandlerAdapter} |
107 |
| - * for processing requests with {@link HttpRequestHandler}s. |
108 |
| - * <li>{@link SimpleControllerHandlerAdapter} |
109 |
| - * for processing requests with interface-based {@link Controller}s. |
| 104 | + * <li>{@link RequestMappingHandlerAdapter} |
| 105 | + * for processing requests with annotated controller methods. |
| 106 | + * <li>{@link HttpRequestHandlerAdapter} |
| 107 | + * for processing requests with {@link HttpRequestHandler}s. |
| 108 | + * <li>{@link SimpleControllerHandlerAdapter} |
| 109 | + * for processing requests with interface-based {@link Controller}s. |
110 | 110 | * </ul>
|
111 | 111 | *
|
112 | 112 | * <p>Registers a {@link HandlerExceptionResolverComposite} with this chain of
|
113 | 113 | * exception resolvers:
|
114 | 114 | * <ul>
|
115 |
| - * <li>{@link ExceptionHandlerExceptionResolver} for handling exceptions |
116 |
| - * through @{@link ExceptionHandler} methods. |
117 |
| - * <li>{@link ResponseStatusExceptionResolver} for exceptions annotated |
118 |
| - * with @{@link ResponseStatus}. |
119 |
| - * <li>{@link DefaultHandlerExceptionResolver} for resolving known Spring |
120 |
| - * exception types |
| 115 | + * <li>{@link ExceptionHandlerExceptionResolver} for handling exceptions |
| 116 | + * through @{@link ExceptionHandler} methods. |
| 117 | + * <li>{@link ResponseStatusExceptionResolver} for exceptions annotated |
| 118 | + * with @{@link ResponseStatus}. |
| 119 | + * <li>{@link DefaultHandlerExceptionResolver} for resolving known Spring |
| 120 | + * exception types |
121 | 121 | * </ul>
|
122 | 122 | *
|
123 | 123 | * <p>Both the {@link RequestMappingHandlerAdapter} and the
|
124 | 124 | * {@link ExceptionHandlerExceptionResolver} are configured with default
|
125 | 125 | * instances of the following by default:
|
126 | 126 | * <ul>
|
127 |
| - * <li>A {@link ContentNegotiationManager} |
128 |
| - * <li>A {@link DefaultFormattingConversionService} |
129 |
| - * <li>A {@link org.springframework.validation.beanvalidation.OptionalValidatorFactoryBean} |
130 |
| - * if a JSR-303 implementation is available on the classpath |
131 |
| - * <li>A range of {@link HttpMessageConverter}s depending on the 3rd party |
132 |
| - * libraries available on the classpath. |
| 127 | + * <li>a {@link ContentNegotiationManager} |
| 128 | + * <li>a {@link DefaultFormattingConversionService} |
| 129 | + * <li>a {@link org.springframework.validation.beanvalidation.OptionalValidatorFactoryBean} |
| 130 | + * if a JSR-303 implementation is available on the classpath |
| 131 | + * <li>a range of {@link HttpMessageConverter}s depending on the third-party |
| 132 | + * libraries available on the classpath. |
133 | 133 | * </ul>
|
134 | 134 | *
|
135 | 135 | * @author Rossen Stoyanchev
|
136 | 136 | * @author Brian Clozel
|
| 137 | + * @author Sebastien Deleuze |
137 | 138 | * @since 3.1
|
138 | 139 | * @see EnableWebMvc
|
139 | 140 | * @see WebMvcConfigurer
|
@@ -373,9 +374,9 @@ protected void configureDefaultServletHandling(DefaultServletHandlerConfigurer c
|
373 | 374 | * through annotated controller methods. Consider overriding one of these
|
374 | 375 | * other more fine-grained methods:
|
375 | 376 | * <ul>
|
376 |
| - * <li>{@link #addArgumentResolvers} for adding custom argument resolvers. |
377 |
| - * <li>{@link #addReturnValueHandlers} for adding custom return value handlers. |
378 |
| - * <li>{@link #configureMessageConverters} for adding custom message converters. |
| 377 | + * <li>{@link #addArgumentResolvers} for adding custom argument resolvers. |
| 378 | + * <li>{@link #addReturnValueHandlers} for adding custom return value handlers. |
| 379 | + * <li>{@link #configureMessageConverters} for adding custom message converters. |
379 | 380 | * </ul>
|
380 | 381 | */
|
381 | 382 | @Bean
|
@@ -653,23 +654,26 @@ protected void configureHandlerExceptionResolvers(List<HandlerExceptionResolver>
|
653 | 654 | * A method available to subclasses for adding default {@link HandlerExceptionResolver}s.
|
654 | 655 | * <p>Adds the following exception resolvers:
|
655 | 656 | * <ul>
|
656 |
| - * <li>{@link ExceptionHandlerExceptionResolver} |
657 |
| - * for handling exceptions through @{@link ExceptionHandler} methods. |
658 |
| - * <li>{@link ResponseStatusExceptionResolver} |
659 |
| - * for exceptions annotated with @{@link ResponseStatus}. |
660 |
| - * <li>{@link DefaultHandlerExceptionResolver} |
661 |
| - * for resolving known Spring exception types |
| 657 | + * <li>{@link ExceptionHandlerExceptionResolver} |
| 658 | + * for handling exceptions through @{@link ExceptionHandler} methods. |
| 659 | + * <li>{@link ResponseStatusExceptionResolver} |
| 660 | + * for exceptions annotated with @{@link ResponseStatus}. |
| 661 | + * <li>{@link DefaultHandlerExceptionResolver} |
| 662 | + * for resolving known Spring exception types |
662 | 663 | * </ul>
|
663 | 664 | */
|
664 | 665 | protected final void addDefaultHandlerExceptionResolvers(List<HandlerExceptionResolver> exceptionResolvers) {
|
665 | 666 | ExceptionHandlerExceptionResolver exceptionHandlerExceptionResolver = new ExceptionHandlerExceptionResolver();
|
666 |
| - exceptionHandlerExceptionResolver.setApplicationContext(this.applicationContext); |
667 | 667 | exceptionHandlerExceptionResolver.setContentNegotiationManager(mvcContentNegotiationManager());
|
668 | 668 | exceptionHandlerExceptionResolver.setMessageConverters(getMessageConverters());
|
| 669 | + exceptionHandlerExceptionResolver.setApplicationContext(this.applicationContext); |
669 | 670 | exceptionHandlerExceptionResolver.afterPropertiesSet();
|
670 |
| - |
671 | 671 | exceptionResolvers.add(exceptionHandlerExceptionResolver);
|
672 |
| - exceptionResolvers.add(new ResponseStatusExceptionResolver()); |
| 672 | + |
| 673 | + ResponseStatusExceptionResolver responseStatusExceptionResolver = new ResponseStatusExceptionResolver(); |
| 674 | + responseStatusExceptionResolver.setMessageSource(this.applicationContext); |
| 675 | + exceptionResolvers.add(responseStatusExceptionResolver); |
| 676 | + |
673 | 677 | exceptionResolvers.add(new DefaultHandlerExceptionResolver());
|
674 | 678 | }
|
675 | 679 |
|
|
0 commit comments