Skip to content

Commit f812998

Browse files
committed
Set ResponseStatusExceptionResolver.messageSource in the MVC Java config
Issue: SPR-12380 (cherry picked from commit aa82da8)
1 parent 7d44c7c commit f812998

File tree

1 file changed

+43
-41
lines changed

1 file changed

+43
-41
lines changed

spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurationSupport.java

Lines changed: 43 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
import org.springframework.validation.Errors;
5252
import org.springframework.validation.MessageCodesResolver;
5353
import org.springframework.validation.Validator;
54-
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
5554
import org.springframework.web.HttpRequestHandler;
5655
import org.springframework.web.accept.ContentNegotiationManager;
5756
import org.springframework.web.bind.WebDataBinder;
@@ -88,49 +87,49 @@
8887
*
8988
* <p>This class registers the following {@link HandlerMapping}s:</p>
9089
* <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.
101100
* </ul>
102101
*
103102
* <p>Registers these {@link HandlerAdapter}s:
104103
* <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.
111110
* </ul>
112111
*
113112
* <p>Registers a {@link HandlerExceptionResolverComposite} with this chain of
114113
* exception resolvers:
115114
* <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
122121
* </ul>
123122
*
124123
* <p>Both the {@link RequestMappingHandlerAdapter} and the
125124
* {@link ExceptionHandlerExceptionResolver} are configured with default
126125
* instances of the following by default:
127126
* <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.
134133
* </ul>
135134
*
136135
* @author Rossen Stoyanchev
@@ -343,9 +342,9 @@ protected void configureDefaultServletHandling(DefaultServletHandlerConfigurer c
343342
* through annotated controller methods. Consider overriding one of these
344343
* other more fine-grained methods:
345344
* <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.
349348
* </ul>
350349
*/
351350
@Bean
@@ -612,23 +611,26 @@ protected void configureHandlerExceptionResolvers(List<HandlerExceptionResolver>
612611
* A method available to subclasses for adding default {@link HandlerExceptionResolver}s.
613612
* <p>Adds the following exception resolvers:
614613
* <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
621620
* </ul>
622621
*/
623622
protected final void addDefaultHandlerExceptionResolvers(List<HandlerExceptionResolver> exceptionResolvers) {
624623
ExceptionHandlerExceptionResolver exceptionHandlerExceptionResolver = new ExceptionHandlerExceptionResolver();
625-
exceptionHandlerExceptionResolver.setApplicationContext(this.applicationContext);
626624
exceptionHandlerExceptionResolver.setContentNegotiationManager(mvcContentNegotiationManager());
627625
exceptionHandlerExceptionResolver.setMessageConverters(getMessageConverters());
626+
exceptionHandlerExceptionResolver.setApplicationContext(this.applicationContext);
628627
exceptionHandlerExceptionResolver.afterPropertiesSet();
629-
630628
exceptionResolvers.add(exceptionHandlerExceptionResolver);
631-
exceptionResolvers.add(new ResponseStatusExceptionResolver());
629+
630+
ResponseStatusExceptionResolver responseStatusExceptionResolver = new ResponseStatusExceptionResolver();
631+
responseStatusExceptionResolver.setMessageSource(this.applicationContext);
632+
exceptionResolvers.add(responseStatusExceptionResolver);
633+
632634
exceptionResolvers.add(new DefaultHandlerExceptionResolver());
633635
}
634636

0 commit comments

Comments
 (0)