|
65 | 65 | import org.springframework.boot.web.servlet.filter.OrderedFormContentFilter;
|
66 | 66 | import org.springframework.boot.web.servlet.server.ServletWebServerFactory;
|
67 | 67 | import org.springframework.context.ApplicationContext;
|
| 68 | +import org.springframework.context.annotation.AnnotationConfigApplicationContext; |
68 | 69 | import org.springframework.context.annotation.Bean;
|
69 | 70 | import org.springframework.context.annotation.Configuration;
|
70 | 71 | import org.springframework.context.annotation.Import;
|
|
89 | 90 | import org.springframework.web.accept.ParameterContentNegotiationStrategy;
|
90 | 91 | import org.springframework.web.bind.annotation.ControllerAdvice;
|
91 | 92 | import org.springframework.web.bind.support.ConfigurableWebBindingInitializer;
|
| 93 | +import org.springframework.web.context.request.RequestAttributes; |
92 | 94 | import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
|
93 | 95 | import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
|
94 | 96 | import org.springframework.web.filter.FormContentFilter;
|
|
102 | 104 | import org.springframework.web.servlet.HandlerExceptionResolver;
|
103 | 105 | import org.springframework.web.servlet.HandlerMapping;
|
104 | 106 | import org.springframework.web.servlet.LocaleResolver;
|
| 107 | +import org.springframework.web.servlet.RequestToViewNameTranslator; |
105 | 108 | import org.springframework.web.servlet.View;
|
106 | 109 | import org.springframework.web.servlet.ViewResolver;
|
107 | 110 | import org.springframework.web.servlet.config.annotation.AsyncSupportConfigurer;
|
@@ -404,6 +407,24 @@ void customFlashMapManagerWithDifferentNameDoesNotReplaceDefaultFlashMapManager(
|
404 | 407 | });
|
405 | 408 | }
|
406 | 409 |
|
| 410 | + @Test |
| 411 | + public void customViewNameTranslatorWithDifferentNameDoesNotReplaceDefaultViewNameTranslator() { |
| 412 | + this.contextRunner.withBean("viewNameTranslator", CustomViewNameTranslator.class, CustomViewNameTranslator::new) |
| 413 | + .run((context) -> { |
| 414 | + assertThat(context.getBean("customViewNameTranslator")).isInstanceOf(CustomViewNameTranslator.class); |
| 415 | + assertThat(context.getBean("viewNameTranslator")).isInstanceOf(SessionFlashMapManager.class); |
| 416 | + }); |
| 417 | + } |
| 418 | + |
| 419 | + @Test |
| 420 | + void customViewNameTranslatorWithDifferentNameReplaceDefaultViewNameTranslator() { |
| 421 | + this.contextRunner.withBean("viewNameTranslator", CustomViewNameTranslator.class, CustomViewNameTranslator::new) |
| 422 | + .run((context) -> { |
| 423 | + assertThat(context).hasSingleBean(RequestToViewNameTranslator.class); |
| 424 | + assertThat(context.getBean("viewNameTranslator")).isInstanceOf(CustomViewNameTranslator.class); |
| 425 | + }); |
| 426 | + } |
| 427 | + |
407 | 428 | @Test
|
408 | 429 | void defaultDateFormat() {
|
409 | 430 | this.contextRunner.run((context) -> {
|
@@ -1458,6 +1479,15 @@ protected void updateFlashMaps(List<FlashMap> flashMaps, HttpServletRequest requ
|
1458 | 1479 |
|
1459 | 1480 | }
|
1460 | 1481 |
|
| 1482 | + static class CustomViewNameTranslator implements RequestToViewNameTranslator { |
| 1483 | + |
| 1484 | + @Override |
| 1485 | + public String getViewName(HttpServletRequest requestAttributes) { |
| 1486 | + return null; |
| 1487 | + } |
| 1488 | + |
| 1489 | + } |
| 1490 | + |
1461 | 1491 | @Configuration(proxyBeanMethods = false)
|
1462 | 1492 | static class ResourceHandlersWithChildAndParentContextConfiguration {
|
1463 | 1493 |
|
|
0 commit comments