commit
7d0b14fe1c
|
|
@ -402,6 +402,7 @@ public class WebMvcAutoConfiguration {
|
|||
new TemplateAvailabilityProviders(applicationContext), applicationContext, getWelcomePage(),
|
||||
this.mvcProperties.getStaticPathPattern());
|
||||
welcomePageHandlerMapping.setInterceptors(getInterceptors(mvcConversionService, mvcResourceUrlProvider));
|
||||
welcomePageHandlerMapping.setCorsConfigurations(getCorsConfigurations());
|
||||
return welcomePageHandlerMapping;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -76,6 +76,7 @@ import org.springframework.web.accept.ParameterContentNegotiationStrategy;
|
|||
import org.springframework.web.accept.PathExtensionContentNegotiationStrategy;
|
||||
import org.springframework.web.bind.support.ConfigurableWebBindingInitializer;
|
||||
import org.springframework.web.context.request.ServletWebRequest;
|
||||
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
|
||||
import org.springframework.web.filter.FormContentFilter;
|
||||
import org.springframework.web.filter.HiddenHttpMethodFilter;
|
||||
import org.springframework.web.filter.RequestContextFilter;
|
||||
|
|
@ -87,6 +88,7 @@ import org.springframework.web.servlet.View;
|
|||
import org.springframework.web.servlet.ViewResolver;
|
||||
import org.springframework.web.servlet.config.annotation.AsyncSupportConfigurer;
|
||||
import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer;
|
||||
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
import org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver;
|
||||
|
|
@ -536,7 +538,19 @@ class WebMvcAutoConfigurationTests {
|
|||
this.contextRunner.withPropertyValues("spring.resources.static-locations:classpath:/welcome-page/")
|
||||
.run((context) -> {
|
||||
assertThat(context).hasSingleBean(WelcomePageHandlerMapping.class);
|
||||
assertThat(context.getBean(WelcomePageHandlerMapping.class).getRootHandler()).isNotNull();
|
||||
WelcomePageHandlerMapping bean = context.getBean(WelcomePageHandlerMapping.class);
|
||||
assertThat(bean.getRootHandler()).isNotNull();
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void welcomePageHandlerIncludesCorsConfiguration() {
|
||||
this.contextRunner.withPropertyValues("spring.resources.static-locations:classpath:/welcome-page/")
|
||||
.withUserConfiguration(CorsConfigurer.class).run((context) -> {
|
||||
WelcomePageHandlerMapping bean = context.getBean(WelcomePageHandlerMapping.class);
|
||||
UrlBasedCorsConfigurationSource source = (UrlBasedCorsConfigurationSource) ReflectionTestUtils
|
||||
.getField(bean, "corsConfigurationSource");
|
||||
assertThat(source.getCorsConfigurations()).containsKey("/**");
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -1157,4 +1171,14 @@ class WebMvcAutoConfigurationTests {
|
|||
|
||||
}
|
||||
|
||||
@Configuration
|
||||
static class CorsConfigurer implements WebMvcConfigurer {
|
||||
|
||||
@Override
|
||||
public void addCorsMappings(CorsRegistry registry) {
|
||||
registry.addMapping("/**").allowedMethods("GET");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue