|
51 | 51 | import org.springframework.validation.Errors;
|
52 | 52 | import org.springframework.validation.MessageCodesResolver;
|
53 | 53 | import org.springframework.validation.Validator;
|
54 |
| -import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean; |
55 | 54 | import org.springframework.web.HttpRequestHandler;
|
56 | 55 | import org.springframework.web.accept.ContentNegotiationManager;
|
57 | 56 | import org.springframework.web.bind.WebDataBinder;
|
|
88 | 87 | *
|
89 | 88 | * <p>This class registers the following {@link HandlerMapping}s:</p>
|
90 | 89 | * <ul>
|
91 |
| - * <li>{@link RequestMappingHandlerMapping} |
92 |
| - * ordered at 0 for mapping requests to annotated controller methods. |
93 |
| - * <li>{@link HandlerMapping} |
94 |
| - * ordered at 1 to map URL paths directly to view names. |
95 |
| - * <li>{@link BeanNameUrlHandlerMapping} |
96 |
| - * ordered at 2 to map URL paths to controller bean names. |
97 |
| - * <li>{@link HandlerMapping} |
98 |
| - * ordered at {@code Integer.MAX_VALUE-1} to serve static resource requests. |
99 |
| - * <li>{@link HandlerMapping} |
100 |
| - * 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. |
101 | 100 | * </ul>
|
102 | 101 | *
|
103 | 102 | * <p>Registers these {@link HandlerAdapter}s:
|
104 | 103 | * <ul>
|
105 |
| - * <li>{@link RequestMappingHandlerAdapter} |
106 |
| - * for processing requests with annotated controller methods. |
107 |
| - * <li>{@link HttpRequestHandlerAdapter} |
108 |
| - * for processing requests with {@link HttpRequestHandler}s. |
109 |
| - * <li>{@link SimpleControllerHandlerAdapter} |
110 |
| - * 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. |
111 | 110 | * </ul>
|
112 | 111 | *
|
113 | 112 | * <p>Registers a {@link HandlerExceptionResolverComposite} with this chain of
|
114 | 113 | * exception resolvers:
|
115 | 114 | * <ul>
|
116 |
| - * <li>{@link ExceptionHandlerExceptionResolver} for handling exceptions |
117 |
| - * through @{@link ExceptionHandler} methods. |
118 |
| - * <li>{@link ResponseStatusExceptionResolver} for exceptions annotated |
119 |
| - * with @{@link ResponseStatus}. |
120 |
| - * <li>{@link DefaultHandlerExceptionResolver} for resolving known Spring |
121 |
| - * 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 |
122 | 121 | * </ul>
|
123 | 122 | *
|
124 | 123 | * <p>Both the {@link RequestMappingHandlerAdapter} and the
|
125 | 124 | * {@link ExceptionHandlerExceptionResolver} are configured with default
|
126 | 125 | * instances of the following by default:
|
127 | 126 | * <ul>
|
128 |
| - * <li>A {@link ContentNegotiationManager} |
129 |
| - * <li>A {@link DefaultFormattingConversionService} |
130 |
| - * <li>A {@link LocalValidatorFactoryBean} if a JSR-303 implementation is |
131 |
| - * available on the classpath |
132 |
| - * <li>A range of {@link HttpMessageConverter}s depending on the 3rd party |
133 |
| - * libraries available on the classpath. |
| 127 | + * <li>a {@link ContentNegotiationManager} |
| 128 | + * <li>a {@link DefaultFormattingConversionService} |
| 129 | + * <li>a {@link org.springframework.validation.beanvalidation.LocalValidatorFactoryBean} |
| 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. |
134 | 133 | * </ul>
|
135 | 134 | *
|
136 | 135 | * @author Rossen Stoyanchev
|
@@ -343,9 +342,9 @@ protected void configureDefaultServletHandling(DefaultServletHandlerConfigurer c
|
343 | 342 | * through annotated controller methods. Consider overriding one of these
|
344 | 343 | * other more fine-grained methods:
|
345 | 344 | * <ul>
|
346 |
| - * <li>{@link #addArgumentResolvers} for adding custom argument resolvers. |
347 |
| - * <li>{@link #addReturnValueHandlers} for adding custom return value handlers. |
348 |
| - * <li>{@link #configureMessageConverters} for adding custom message converters. |
| 345 | + * <li>{@link #addArgumentResolvers} for adding custom argument resolvers. |
| 346 | + * <li>{@link #addReturnValueHandlers} for adding custom return value handlers. |
| 347 | + * <li>{@link #configureMessageConverters} for adding custom message converters. |
349 | 348 | * </ul>
|
350 | 349 | */
|
351 | 350 | @Bean
|
@@ -612,23 +611,26 @@ protected void configureHandlerExceptionResolvers(List<HandlerExceptionResolver>
|
612 | 611 | * A method available to subclasses for adding default {@link HandlerExceptionResolver}s.
|
613 | 612 | * <p>Adds the following exception resolvers:
|
614 | 613 | * <ul>
|
615 |
| - * <li>{@link ExceptionHandlerExceptionResolver} |
616 |
| - * for handling exceptions through @{@link ExceptionHandler} methods. |
617 |
| - * <li>{@link ResponseStatusExceptionResolver} |
618 |
| - * for exceptions annotated with @{@link ResponseStatus}. |
619 |
| - * <li>{@link DefaultHandlerExceptionResolver} |
620 |
| - * for resolving known Spring exception types |
| 614 | + * <li>{@link ExceptionHandlerExceptionResolver} |
| 615 | + * for handling exceptions through @{@link ExceptionHandler} methods. |
| 616 | + * <li>{@link ResponseStatusExceptionResolver} |
| 617 | + * for exceptions annotated with @{@link ResponseStatus}. |
| 618 | + * <li>{@link DefaultHandlerExceptionResolver} |
| 619 | + * for resolving known Spring exception types |
621 | 620 | * </ul>
|
622 | 621 | */
|
623 | 622 | protected final void addDefaultHandlerExceptionResolvers(List<HandlerExceptionResolver> exceptionResolvers) {
|
624 | 623 | ExceptionHandlerExceptionResolver exceptionHandlerExceptionResolver = new ExceptionHandlerExceptionResolver();
|
625 |
| - exceptionHandlerExceptionResolver.setApplicationContext(this.applicationContext); |
626 | 624 | exceptionHandlerExceptionResolver.setContentNegotiationManager(mvcContentNegotiationManager());
|
627 | 625 | exceptionHandlerExceptionResolver.setMessageConverters(getMessageConverters());
|
| 626 | + exceptionHandlerExceptionResolver.setApplicationContext(this.applicationContext); |
628 | 627 | exceptionHandlerExceptionResolver.afterPropertiesSet();
|
629 |
| - |
630 | 628 | exceptionResolvers.add(exceptionHandlerExceptionResolver);
|
631 |
| - exceptionResolvers.add(new ResponseStatusExceptionResolver()); |
| 629 | + |
| 630 | + ResponseStatusExceptionResolver responseStatusExceptionResolver = new ResponseStatusExceptionResolver(); |
| 631 | + responseStatusExceptionResolver.setMessageSource(this.applicationContext); |
| 632 | + exceptionResolvers.add(responseStatusExceptionResolver); |
| 633 | + |
632 | 634 | exceptionResolvers.add(new DefaultHandlerExceptionResolver());
|
633 | 635 | }
|
634 | 636 |
|
|
0 commit comments