diff --git a/spring-web-reactive/src/main/java/org/springframework/web/reactive/config/ResourceHandlerRegistry.java b/spring-web-reactive/src/main/java/org/springframework/web/reactive/config/ResourceHandlerRegistry.java index 803f29463aa..9b647146748 100644 --- a/spring-web-reactive/src/main/java/org/springframework/web/reactive/config/ResourceHandlerRegistry.java +++ b/spring-web-reactive/src/main/java/org/springframework/web/reactive/config/ResourceHandlerRegistry.java @@ -150,7 +150,7 @@ public class ResourceHandlerRegistry { } SimpleUrlHandlerMapping handlerMapping = new SimpleUrlHandlerMapping(); - handlerMapping.setOrder(order); + handlerMapping.setOrder(this.order); handlerMapping.setUrlMap(urlMap); return handlerMapping; } diff --git a/spring-web-reactive/src/main/java/org/springframework/web/reactive/config/WebReactiveConfiguration.java b/spring-web-reactive/src/main/java/org/springframework/web/reactive/config/WebReactiveConfiguration.java index d1feb9f3758..643da2ef10c 100644 --- a/spring-web-reactive/src/main/java/org/springframework/web/reactive/config/WebReactiveConfiguration.java +++ b/spring-web-reactive/src/main/java/org/springframework/web/reactive/config/WebReactiveConfiguration.java @@ -198,11 +198,12 @@ public class WebReactiveConfiguration implements ApplicationContextAware { AbstractHandlerMapping handlerMapping = registry.getHandlerMapping(); if (handlerMapping != null) { - if (getPathMatchConfigurer() != null) { - handlerMapping.setPathMatcher(getPathMatchConfigurer().getPathMatcher()); + PathMatchConfigurer pathMatchConfigurer = getPathMatchConfigurer(); + if (pathMatchConfigurer.getPathMatcher() != null) { + handlerMapping.setPathMatcher(pathMatchConfigurer.getPathMatcher()); } - if (getPathMatchConfigurer() != null) { - handlerMapping.setPathHelper(getPathMatchConfigurer().getPathHelper()); + if (pathMatchConfigurer.getPathHelper() != null) { + handlerMapping.setPathHelper(pathMatchConfigurer.getPathHelper()); } } else { diff --git a/spring-web-reactive/src/test/java/org/springframework/web/reactive/config/WebReactiveConfigurationTests.java b/spring-web-reactive/src/test/java/org/springframework/web/reactive/config/WebReactiveConfigurationTests.java index 5023f9cd5d4..4ab112f83d3 100644 --- a/spring-web-reactive/src/test/java/org/springframework/web/reactive/config/WebReactiveConfigurationTests.java +++ b/spring-web-reactive/src/test/java/org/springframework/web/reactive/config/WebReactiveConfigurationTests.java @@ -50,6 +50,8 @@ import org.springframework.util.MimeTypeUtils; import org.springframework.validation.Validator; import org.springframework.validation.beanvalidation.OptionalValidatorFactoryBean; import org.springframework.web.reactive.accept.RequestedContentTypeResolver; +import org.springframework.web.reactive.handler.AbstractHandlerMapping; +import org.springframework.web.reactive.handler.SimpleUrlHandlerMapping; import org.springframework.web.reactive.result.method.annotation.RequestMappingHandlerAdapter; import org.springframework.web.reactive.result.method.annotation.RequestMappingHandlerMapping; import org.springframework.web.reactive.result.method.annotation.ResponseBodyResultHandler; @@ -61,6 +63,7 @@ import org.springframework.web.reactive.result.view.ViewResolver; import org.springframework.web.reactive.result.view.freemarker.FreeMarkerConfigurer; import org.springframework.web.reactive.result.view.freemarker.FreeMarkerViewResolver; import org.springframework.web.server.ServerWebExchange; +import org.springframework.web.server.WebHandler; import org.springframework.web.server.adapter.DefaultServerWebExchange; import org.springframework.web.server.session.MockWebSessionManager; @@ -246,6 +249,24 @@ public class WebReactiveConfigurationTests { assertEquals(type, views.get(0).getSupportedMediaTypes().get(0)); } + @Test + public void resourceHandler() throws Exception { + ApplicationContext context = loadConfig(CustomResourceHandlingConfig.class); + + String name = "resourceHandlerMapping"; + AbstractHandlerMapping handlerMapping = context.getBean(name, AbstractHandlerMapping.class); + assertNotNull(handlerMapping); + + assertEquals(Ordered.LOWEST_PRECEDENCE -1, handlerMapping.getOrder()); + + assertNotNull(handlerMapping.getPathHelper()); + assertNotNull(handlerMapping.getPathMatcher()); + + SimpleUrlHandlerMapping urlHandlerMapping = (SimpleUrlHandlerMapping) handlerMapping; + WebHandler webHandler = (WebHandler) urlHandlerMapping.getUrlMap().get("/images/**"); + assertNotNull(webHandler); + } + private void assertHasMessageReader(List> readers, Class clazz, MediaType mediaType) { ResolvableType type = ResolvableType.forClass(clazz); @@ -321,6 +342,16 @@ public class WebReactiveConfigurationTests { } + @Configuration + static class CustomResourceHandlingConfig extends WebReactiveConfiguration { + + @Override + protected void addResourceHandlers(ResourceHandlerRegistry registry) { + registry.addResourceHandler("/images/**").addResourceLocations("/images/"); + } + } + + @XmlRootElement static class TestBean { }