From 816a58fcf91b7cdb27b430ae6b96c9143a67d124 Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Fri, 22 Sep 2017 15:15:41 -0400 Subject: [PATCH] RouterFunctionMapping provides getter for RouterFunction Issue: SPR-15991 --- .../server/support/RouterFunctionMapping.java | 12 ++++++++++++ .../web/reactive/DispatcherHandlerTests.java | 6 +----- .../web/servlet/DispatcherServlet.java | 9 +++++---- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/support/RouterFunctionMapping.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/support/RouterFunctionMapping.java index 63c6a4f037..ef59f7f301 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/support/RouterFunctionMapping.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/support/RouterFunctionMapping.java @@ -70,6 +70,18 @@ public class RouterFunctionMapping extends AbstractHandlerMapping implements Ini } + /** + * Return the configured {@link RouterFunction}. + *

Note: When router functions are detected from the + * ApplicationContext, this method may return {@code null} if invoked + * prior to {@link #afterPropertiesSet()}. + * @return the router function or {@code null} + */ + @Nullable + public RouterFunction getRouterFunction() { + return this.routerFunction; + } + /** * Configure HTTP message readers to de-serialize the request body with. *

By default this is set to the {@link ServerCodecConfigurer}'s defaults. diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/DispatcherHandlerTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/DispatcherHandlerTests.java index c2cff59cbc..85adcad752 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/DispatcherHandlerTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/DispatcherHandlerTests.java @@ -17,18 +17,14 @@ package org.springframework.web.reactive; import java.nio.charset.StandardCharsets; import java.time.Duration; -import java.util.function.Function; import java.util.function.Supplier; import org.junit.Test; -import org.mockito.MockSettings; -import org.mockito.Mockito; import reactor.core.publisher.Mono; import org.springframework.context.support.StaticApplicationContext; import org.springframework.core.MethodParameter; import org.springframework.core.Ordered; -import org.springframework.core.codec.CharSequenceEncoder; import org.springframework.core.io.buffer.DataBuffer; import org.springframework.core.io.buffer.DefaultDataBufferFactory; import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest; @@ -43,7 +39,7 @@ import static org.mockito.Mockito.when; import static org.mockito.Mockito.withSettings; /** - * + * Unit tests for {@link DispatcherHandler}. * @author Rossen Stoyanchev */ public class DispatcherHandlerTests { diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/DispatcherServlet.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/DispatcherServlet.java index 3b3d151f2e..7f08043eca 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/DispatcherServlet.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/DispatcherServlet.java @@ -774,13 +774,14 @@ public class DispatcherServlet extends FrameworkServlet { * Return the configured {@link HandlerMapping} beans that were detected by * type in the {@link WebApplicationContext} or initialized based on the * default set of strategies from {@literal DispatcherServlet.properties}. - * @return immutable list with the configured mappings or an empty list + *

Note: This method may return {@code null} if invoked + * prior to {@link #onRefresh(ApplicationContext)}. + * @return immutable list with the configured mappings or {@code null} * @since 5.0 */ + @Nullable public List getHandlerMappings() { - return this.handlerMappings != null ? - Collections.unmodifiableList(this.handlerMappings) : - Collections.emptyList(); + return this.handlerMappings != null ? Collections.unmodifiableList(this.handlerMappings) : null; } /**