|
8 | 8 | .ResourceHandlerRegistry;
|
9 | 9 | import org.springframework.web.servlet.config.annotation
|
10 | 10 | .WebMvcConfigurationSupport;
|
| 11 | +import org.springframework.web.servlet.mvc.method.annotation |
| 12 | + .RequestMappingHandlerAdapter; |
11 | 13 | import org.springframework.web.servlet.mvc.method.annotation
|
12 | 14 | .RequestMappingHandlerMapping;
|
| 15 | + |
| 16 | +import java.util.List; |
| 17 | + |
13 | 18 | import org.springframework.beans.factory.annotation.Autowired;
|
14 | 19 | import org.springframework.beans.factory.annotation.Value;
|
15 | 20 | import org.springframework.context.annotation.Bean;
|
16 | 21 | import org.springframework.context.annotation.Configuration;
|
17 | 22 | import org.springframework.context.support
|
18 | 23 | .PropertySourcesPlaceholderConfigurer;
|
| 24 | +import org.springframework.http.converter.HttpMessageConverter; |
19 | 25 |
|
20 | 26 | /** Custom configuration for the dispatcher servlet application context
|
21 | 27 | *
|
@@ -60,6 +66,31 @@ protected RequestMappingHandlerMapping createRequestMappingHandlerMapping() {
|
60 | 66 | return result;
|
61 | 67 | }
|
62 | 68 |
|
| 69 | + /** A handler adapter bean that can be configured with the message converters |
| 70 | + * found in the application context hierarchy. |
| 71 | + * |
| 72 | + * If there is at least one message converter up in the application context |
| 73 | + * hierarchy, this bean will override the default message converters for the |
| 74 | + * handler adapter. |
| 75 | + * |
| 76 | + * @param converters a list of message converters. If empty, the handler |
| 77 | + * adapter uses the default converters (see WebMvcConfigurationSupport). |
| 78 | + * |
| 79 | + * @return a RequestMappingHandlerAdapter configured with any message |
| 80 | + * converter found in the application context. Never returns null. |
| 81 | + */ |
| 82 | + @Bean |
| 83 | + public RequestMappingHandlerAdapter requestMappingHandlerAdapter( |
| 84 | + final List<HttpMessageConverter<?>> converters) { |
| 85 | + RequestMappingHandlerAdapter adapter; |
| 86 | + adapter = super.requestMappingHandlerAdapter(); |
| 87 | + |
| 88 | + if (!converters.isEmpty()) { |
| 89 | + adapter.setMessageConverters(converters); |
| 90 | + } |
| 91 | + return adapter; |
| 92 | + } |
| 93 | + |
63 | 94 | /** Registers handlers that serve the module static content.
|
64 | 95 | */
|
65 | 96 | @Override
|
|
0 commit comments