|
76 | 76 | import org.springframework.web.accept.PathExtensionContentNegotiationStrategy;
|
77 | 77 | import org.springframework.web.bind.support.ConfigurableWebBindingInitializer;
|
78 | 78 | import org.springframework.web.context.request.ServletWebRequest;
|
| 79 | +import org.springframework.web.cors.UrlBasedCorsConfigurationSource; |
79 | 80 | import org.springframework.web.filter.FormContentFilter;
|
80 | 81 | import org.springframework.web.filter.HiddenHttpMethodFilter;
|
81 | 82 | import org.springframework.web.filter.RequestContextFilter;
|
|
87 | 88 | import org.springframework.web.servlet.ViewResolver;
|
88 | 89 | import org.springframework.web.servlet.config.annotation.AsyncSupportConfigurer;
|
89 | 90 | import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer;
|
| 91 | +import org.springframework.web.servlet.config.annotation.CorsRegistry; |
90 | 92 | import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
91 | 93 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
92 | 94 | import org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver;
|
@@ -536,7 +538,19 @@ void welcomePageHandlerMappingIsAutoConfigured() {
|
536 | 538 | this.contextRunner.withPropertyValues("spring.resources.static-locations:classpath:/welcome-page/")
|
537 | 539 | .run((context) -> {
|
538 | 540 | assertThat(context).hasSingleBean(WelcomePageHandlerMapping.class);
|
539 |
| - assertThat(context.getBean(WelcomePageHandlerMapping.class).getRootHandler()).isNotNull(); |
| 541 | + WelcomePageHandlerMapping bean = context.getBean(WelcomePageHandlerMapping.class); |
| 542 | + assertThat(bean.getRootHandler()).isNotNull(); |
| 543 | + }); |
| 544 | + } |
| 545 | + |
| 546 | + @Test |
| 547 | + void welcomePageHandlerIncludesCorsConfiguration() { |
| 548 | + this.contextRunner.withPropertyValues("spring.resources.static-locations:classpath:/welcome-page/") |
| 549 | + .withUserConfiguration(CorsConfigurer.class).run((context) -> { |
| 550 | + WelcomePageHandlerMapping bean = context.getBean(WelcomePageHandlerMapping.class); |
| 551 | + UrlBasedCorsConfigurationSource source = (UrlBasedCorsConfigurationSource) ReflectionTestUtils |
| 552 | + .getField(bean, "corsConfigurationSource"); |
| 553 | + assertThat(source.getCorsConfigurations()).containsKey("/**"); |
540 | 554 | });
|
541 | 555 | }
|
542 | 556 |
|
@@ -1157,4 +1171,14 @@ public Example parse(String source, Locale locale) {
|
1157 | 1171 |
|
1158 | 1172 | }
|
1159 | 1173 |
|
| 1174 | + @Configuration |
| 1175 | + static class CorsConfigurer implements WebMvcConfigurer { |
| 1176 | + |
| 1177 | + @Override |
| 1178 | + public void addCorsMappings(CorsRegistry registry) { |
| 1179 | + registry.addMapping("/**").allowedMethods("GET"); |
| 1180 | + } |
| 1181 | + |
| 1182 | + } |
| 1183 | + |
1160 | 1184 | }
|
0 commit comments