Merge branch '2.3.x'

Closes gh-21925
pull/21936/head
Brian Clozel 4 years ago
commit e438864ad9

@ -63,6 +63,7 @@ import org.springframework.web.reactive.config.WebFluxConfigurationSupport;
import org.springframework.web.reactive.config.WebFluxConfigurer;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.ServerResponse;
import org.springframework.web.reactive.function.server.support.RouterFunctionMapping;
import org.springframework.web.reactive.result.method.HandlerMethodArgumentResolver;
import org.springframework.web.reactive.result.method.annotation.ArgumentResolverConfigurer;
import org.springframework.web.reactive.result.method.annotation.RequestMappingHandlerAdapter;
@ -101,12 +102,18 @@ public class WebFluxAutoConfiguration {
public static class WelcomePageConfiguration {
@Bean
public RouterFunction<ServerResponse> welcomePageRouterFunction(ApplicationContext applicationContext,
public RouterFunctionMapping welcomePageRouterFunctionMapping(ApplicationContext applicationContext,
WebFluxProperties webFluxProperties, ResourceProperties resourceProperties) {
WelcomePageRouterFunctionFactory factory = new WelcomePageRouterFunctionFactory(
new TemplateAvailabilityProviders(applicationContext), applicationContext,
resourceProperties.getStaticLocations(), webFluxProperties.getStaticPathPattern());
return factory.createRouterFunction();
RouterFunction<ServerResponse> routerFunction = factory.createRouterFunction();
if (routerFunction != null) {
RouterFunctionMapping routerFunctionMapping = new RouterFunctionMapping(routerFunction);
routerFunctionMapping.setOrder(1);
return routerFunctionMapping;
}
return null;
}
}

@ -62,6 +62,7 @@ import org.springframework.web.reactive.HandlerMapping;
import org.springframework.web.reactive.accept.RequestedContentTypeResolver;
import org.springframework.web.reactive.config.WebFluxConfigurationSupport;
import org.springframework.web.reactive.config.WebFluxConfigurer;
import org.springframework.web.reactive.function.server.support.RouterFunctionMapping;
import org.springframework.web.reactive.handler.SimpleUrlHandlerMapping;
import org.springframework.web.reactive.resource.CachingResourceResolver;
import org.springframework.web.reactive.resource.CachingResourceTransformer;
@ -108,6 +109,7 @@ class WebFluxAutoConfigurationTests {
assertThat(context).getBeans(RequestMappingHandlerMapping.class).hasSize(1);
assertThat(context).getBeans(RequestMappingHandlerAdapter.class).hasSize(1);
assertThat(context).getBeans(RequestedContentTypeResolver.class).hasSize(1);
assertThat(context).getBeans(RouterFunctionMapping.class).hasSize(1);
assertThat(context.getBean("resourceHandlerMapping", HandlerMapping.class)).isNotNull();
});
}
@ -440,6 +442,15 @@ class WebFluxAutoConfigurationTests {
});
}
@Test
void welcomePageHandlerMapping() {
this.contextRunner.withPropertyValues("spring.resources.static-locations=classpath:/welcome-page/").run((context) -> {
assertThat(context).getBeans(RouterFunctionMapping.class).hasSize(2);
assertThat(context.getBean("welcomePageRouterFunctionMapping", HandlerMapping.class)).isNotNull()
.extracting("order").isEqualTo(1);
});
}
private Map<PathPattern, Object> getHandlerMap(ApplicationContext context) {
HandlerMapping mapping = context.getBean("resourceHandlerMapping", HandlerMapping.class);
if (mapping instanceof SimpleUrlHandlerMapping) {

Loading…
Cancel
Save