|
71 | 71 | import org.springframework.web.servlet.LocaleResolver;
|
72 | 72 | import org.springframework.web.servlet.View;
|
73 | 73 | import org.springframework.web.servlet.ViewResolver;
|
| 74 | +import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer; |
74 | 75 | import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
75 | 76 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
76 | 77 | import org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver;
|
@@ -809,6 +810,18 @@ public void queryParameterContentNegotiation() {
|
809 | 810 | });
|
810 | 811 | }
|
811 | 812 |
|
| 813 | + @Test |
| 814 | + public void customConfigurerAppliedAfterAutoConfig() { |
| 815 | + this.contextRunner |
| 816 | + .withUserConfiguration(CustomConfigurer.class) |
| 817 | + .run((context) -> { |
| 818 | + ContentNegotiationManager manager = context.getBean(ContentNegotiationManager.class); |
| 819 | + assertThat(manager.getStrategies()).anyMatch(strategy -> |
| 820 | + WebMvcAutoConfiguration.OptionalPathExtensionContentNegotiationStrategy.class |
| 821 | + .isAssignableFrom(strategy.getClass())); |
| 822 | + }); |
| 823 | + } |
| 824 | + |
812 | 825 | private void assertCacheControl(AssertableWebApplicationContext context) {
|
813 | 826 | Map<String, Object> handlerMap = getHandlerMap(
|
814 | 827 | context.getBean("resourceHandlerMapping", HandlerMapping.class));
|
@@ -1086,4 +1099,13 @@ public HttpMessageConverter<?> customHttpMessageConverter(
|
1086 | 1099 |
|
1087 | 1100 | }
|
1088 | 1101 |
|
| 1102 | + @Configuration |
| 1103 | + static class CustomConfigurer implements WebMvcConfigurer { |
| 1104 | + |
| 1105 | + @Override |
| 1106 | + public void configureContentNegotiation(ContentNegotiationConfigurer configurer) { |
| 1107 | + configurer.favorPathExtension(true); |
| 1108 | + } |
| 1109 | + } |
| 1110 | + |
1089 | 1111 | }
|
0 commit comments