|
102 | 102 | import org.springframework.web.servlet.HandlerExceptionResolver;
|
103 | 103 | import org.springframework.web.servlet.HandlerMapping;
|
104 | 104 | import org.springframework.web.servlet.LocaleResolver;
|
| 105 | +import org.springframework.web.servlet.RequestToViewNameTranslator; |
105 | 106 | import org.springframework.web.servlet.View;
|
106 | 107 | import org.springframework.web.servlet.ViewResolver;
|
107 | 108 | import org.springframework.web.servlet.config.annotation.AsyncSupportConfigurer;
|
|
136 | 137 | import org.springframework.web.servlet.support.SessionFlashMapManager;
|
137 | 138 | import org.springframework.web.servlet.view.AbstractView;
|
138 | 139 | import org.springframework.web.servlet.view.ContentNegotiatingViewResolver;
|
| 140 | +import org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator; |
139 | 141 | import org.springframework.web.util.UrlPathHelper;
|
140 | 142 |
|
141 | 143 | import static org.assertj.core.api.Assertions.assertThat;
|
@@ -404,6 +406,26 @@ void customFlashMapManagerWithDifferentNameDoesNotReplaceDefaultFlashMapManager(
|
404 | 406 | });
|
405 | 407 | }
|
406 | 408 |
|
| 409 | + @Test |
| 410 | + void customViewNameTranslatorWithMatchingNameReplacesDefaultViewNameTranslator() { |
| 411 | + this.contextRunner.withBean("viewNameTranslator", CustomViewNameTranslator.class, CustomViewNameTranslator::new) |
| 412 | + .run((context) -> { |
| 413 | + assertThat(context).hasSingleBean(RequestToViewNameTranslator.class); |
| 414 | + assertThat(context.getBean("viewNameTranslator")).isInstanceOf(CustomViewNameTranslator.class); |
| 415 | + }); |
| 416 | + } |
| 417 | + |
| 418 | + @Test |
| 419 | + void customViewNameTranslatorWithDifferentNameDoesNotReplaceDefaultViewNameTranslator() { |
| 420 | + this.contextRunner |
| 421 | + .withBean("customViewNameTranslator", CustomViewNameTranslator.class, CustomViewNameTranslator::new) |
| 422 | + .run((context) -> { |
| 423 | + assertThat(context.getBean("customViewNameTranslator")).isInstanceOf(CustomViewNameTranslator.class); |
| 424 | + assertThat(context.getBean("viewNameTranslator")) |
| 425 | + .isInstanceOf(DefaultRequestToViewNameTranslator.class); |
| 426 | + }); |
| 427 | + } |
| 428 | + |
407 | 429 | @Test
|
408 | 430 | void defaultDateFormat() {
|
409 | 431 | this.contextRunner.run((context) -> {
|
@@ -1458,6 +1480,15 @@ protected void updateFlashMaps(List<FlashMap> flashMaps, HttpServletRequest requ
|
1458 | 1480 |
|
1459 | 1481 | }
|
1460 | 1482 |
|
| 1483 | + static class CustomViewNameTranslator implements RequestToViewNameTranslator { |
| 1484 | + |
| 1485 | + @Override |
| 1486 | + public String getViewName(HttpServletRequest requestAttributes) { |
| 1487 | + return null; |
| 1488 | + } |
| 1489 | + |
| 1490 | + } |
| 1491 | + |
1461 | 1492 | @Configuration(proxyBeanMethods = false)
|
1462 | 1493 | static class ResourceHandlersWithChildAndParentContextConfiguration {
|
1463 | 1494 |
|
|
0 commit comments