diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/MappingsEndpointServletDocumentationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/MappingsEndpointServletDocumentationTests.java index f3838b16b3..6ed5e3598c 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/MappingsEndpointServletDocumentationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/MappingsEndpointServletDocumentationTests.java @@ -63,6 +63,7 @@ import static org.springframework.web.servlet.function.RequestPredicates.GET; * Tests for generating documentation describing {@link MappingsEndpoint}. * * @author Andy Wilkinson + * @author Xiong Tang */ @ExtendWith(RestDocumentationExtension.class) @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) @@ -136,10 +137,10 @@ class MappingsEndpointServletDocumentationTests extends AbstractEndpointDocument .description("Descriptor of the method as specified in the Java Language Specification.")); List handlerFunction = List.of( fieldWithPath("*.[].details.handlerFunction").optional() - .type(JsonFieldType.OBJECT) - .description("Details of the function, if any, that will handle requests to this mapping."), + .type(JsonFieldType.OBJECT) + .description("Details of the function, if any, that will handle requests to this mapping."), fieldWithPath("*.[].details.handlerFunction.className").type(JsonFieldType.STRING) - .description("Fully qualified name of the class of the function.")); + .description("Fully qualified name of the class of the function.")); dispatcherServletFields.addAll(handlerFunction); dispatcherServletFields.addAll(handlerMethod); dispatcherServletFields.addAll(requestMappingConditions); diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/web/mappings/servlet/DispatcherServletMappingDetails.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/web/mappings/servlet/DispatcherServletMappingDetails.java index 05326ea505..786ddc5519 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/web/mappings/servlet/DispatcherServletMappingDetails.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/web/mappings/servlet/DispatcherServletMappingDetails.java @@ -23,6 +23,7 @@ import org.springframework.web.servlet.DispatcherServlet; * Details of a {@link DispatcherServlet} mapping. * * @author Andy Wilkinson + * @author Xiong Tang * @since 2.0.0 */ public class DispatcherServletMappingDetails { diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/web/mappings/servlet/DispatcherServletsMappingDescriptionProvider.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/web/mappings/servlet/DispatcherServletsMappingDescriptionProvider.java index 452ca506f7..2225550c1b 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/web/mappings/servlet/DispatcherServletsMappingDescriptionProvider.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/web/mappings/servlet/DispatcherServletsMappingDescriptionProvider.java @@ -60,6 +60,7 @@ import org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMappi * * @author Andy Wilkinson * @author Stephane Nicoll + * @author Xiong Tang * @since 2.0.0 */ @ImportRuntimeHints(DispatcherServletsMappingDescriptionProviderRuntimeHints.class) diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/web/mappings/servlet/HandlerFunctionDescription.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/web/mappings/servlet/HandlerFunctionDescription.java index 26df168bae..f62a4f55f4 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/web/mappings/servlet/HandlerFunctionDescription.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/web/mappings/servlet/HandlerFunctionDescription.java @@ -16,7 +16,6 @@ package org.springframework.boot.actuate.web.mappings.servlet; - import org.springframework.web.servlet.function.HandlerFunction; /** diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/web/mappings/MappingsEndpointTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/web/mappings/MappingsEndpointTests.java index f99745216b..5516fa69f5 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/web/mappings/MappingsEndpointTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/web/mappings/MappingsEndpointTests.java @@ -57,6 +57,8 @@ import org.springframework.web.servlet.DispatcherServlet; import org.springframework.web.servlet.config.annotation.EnableWebMvc; import org.springframework.web.servlet.config.annotation.PathMatchConfigurer; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; +import org.springframework.web.servlet.function.RequestPredicates; +import org.springframework.web.servlet.function.RouterFunctions; import org.springframework.web.util.pattern.PathPatternParser; import static org.assertj.core.api.Assertions.assertThat; @@ -71,6 +73,7 @@ import static org.springframework.web.reactive.function.server.RouterFunctions.r * * @author Andy Wilkinson * @author Stephane Nicoll + * @author Xiong Tang */ class MappingsEndpointTests { @@ -88,7 +91,7 @@ class MappingsEndpointTests { "dispatcherServlets"); assertThat(dispatcherServlets).containsOnlyKeys("dispatcherServlet"); List handlerMappings = dispatcherServlets.get("dispatcherServlet"); - assertThat(handlerMappings).hasSize(3); + assertThat(handlerMappings).hasSize(4); List servlets = mappings(contextMappings, "servlets"); assertThat(servlets).hasSize(1); List filters = mappings(contextMappings, "servletFilters"); @@ -111,7 +114,7 @@ class MappingsEndpointTests { "dispatcherServlets"); assertThat(dispatcherServlets).containsOnlyKeys("dispatcherServlet"); List handlerMappings = dispatcherServlets.get("dispatcherServlet"); - assertThat(handlerMappings).hasSize(3); + assertThat(handlerMappings).hasSize(4); List servlets = mappings(contextMappings, "servlets"); assertThat(servlets).hasSize(1); List filters = mappings(contextMappings, "servletFilters"); @@ -131,9 +134,9 @@ class MappingsEndpointTests { "dispatcherServlets"); assertThat(dispatcherServlets).containsOnlyKeys("dispatcherServlet", "customDispatcherServletRegistration", "anotherDispatcherServletRegistration"); - assertThat(dispatcherServlets.get("dispatcherServlet")).hasSize(3); - assertThat(dispatcherServlets.get("customDispatcherServletRegistration")).hasSize(3); - assertThat(dispatcherServlets.get("anotherDispatcherServletRegistration")).hasSize(3); + assertThat(dispatcherServlets.get("dispatcherServlet")).hasSize(4); + assertThat(dispatcherServlets.get("customDispatcherServletRegistration")).hasSize(4); + assertThat(dispatcherServlets.get("anotherDispatcherServletRegistration")).hasSize(4); }); } @@ -248,18 +251,26 @@ class MappingsEndpointTests { return dispatcherServlet; } + @Bean + org.springframework.web.servlet.function.RouterFunction routerFunction() { + return RouterFunctions + .route(RequestPredicates.GET("/one"), + (request) -> org.springframework.web.servlet.function.ServerResponse.ok().build()) + .andRoute(RequestPredicates.POST("/two"), + (request) -> org.springframework.web.servlet.function.ServerResponse.ok().build()); + } + @RequestMapping("/three") void three() { } @Bean - org.springframework.web.servlet.function.RouterFunction routerFunction() { - return org.springframework.web.servlet.function.RouterFunctions - .route(org.springframework.web.servlet.function.RequestPredicates.GET("/one"), - (request) -> org.springframework.web.servlet.function.ServerResponse.ok().build()) - .andRoute(org.springframework.web.servlet.function.RequestPredicates.POST("/two"), - (request) -> org.springframework.web.servlet.function.ServerResponse.ok().build()); + org.springframework.web.servlet.function.RouterFunction routerFunctionWithAttributes() { + return RouterFunctions + .route(RequestPredicates.GET("/four"), + (request) -> org.springframework.web.servlet.function.ServerResponse.ok().build()) + .withAttribute("test", "test"); } }