Skip to content

Commit b2ba2a5

Browse files
committed
Polish "Add support for MVC router functions to mappings endpoint"
See gh-44163
1 parent a747bcf commit b2ba2a5

File tree

5 files changed

+28
-15
lines changed

5 files changed

+28
-15
lines changed

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/MappingsEndpointServletDocumentationTests.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
* Tests for generating documentation describing {@link MappingsEndpoint}.
6464
*
6565
* @author Andy Wilkinson
66+
* @author Xiong Tang
6667
*/
6768
@ExtendWith(RestDocumentationExtension.class)
6869
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@@ -136,10 +137,10 @@ void mappings() {
136137
.description("Descriptor of the method as specified in the Java Language Specification."));
137138
List<FieldDescriptor> handlerFunction = List.of(
138139
fieldWithPath("*.[].details.handlerFunction").optional()
139-
.type(JsonFieldType.OBJECT)
140-
.description("Details of the function, if any, that will handle requests to this mapping."),
140+
.type(JsonFieldType.OBJECT)
141+
.description("Details of the function, if any, that will handle requests to this mapping."),
141142
fieldWithPath("*.[].details.handlerFunction.className").type(JsonFieldType.STRING)
142-
.description("Fully qualified name of the class of the function."));
143+
.description("Fully qualified name of the class of the function."));
143144
dispatcherServletFields.addAll(handlerFunction);
144145
dispatcherServletFields.addAll(handlerMethod);
145146
dispatcherServletFields.addAll(requestMappingConditions);

spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/web/mappings/servlet/DispatcherServletMappingDetails.java

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
* Details of a {@link DispatcherServlet} mapping.
2424
*
2525
* @author Andy Wilkinson
26+
* @author Xiong Tang
2627
* @since 2.0.0
2728
*/
2829
public class DispatcherServletMappingDetails {

spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/web/mappings/servlet/DispatcherServletsMappingDescriptionProvider.java

+1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
*
6161
* @author Andy Wilkinson
6262
* @author Stephane Nicoll
63+
* @author Xiong Tang
6364
* @since 2.0.0
6465
*/
6566
@ImportRuntimeHints(DispatcherServletsMappingDescriptionProviderRuntimeHints.class)

spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/web/mappings/servlet/HandlerFunctionDescription.java

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package org.springframework.boot.actuate.web.mappings.servlet;
1818

19-
2019
import org.springframework.web.servlet.function.HandlerFunction;
2120

2221
/**

spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/web/mappings/MappingsEndpointTests.java

+22-11
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@
5757
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
5858
import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
5959
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
60+
import org.springframework.web.servlet.function.RequestPredicates;
61+
import org.springframework.web.servlet.function.RouterFunctions;
6062
import org.springframework.web.util.pattern.PathPatternParser;
6163

6264
import static org.assertj.core.api.Assertions.assertThat;
@@ -71,6 +73,7 @@
7173
*
7274
* @author Andy Wilkinson
7375
* @author Stephane Nicoll
76+
* @author Xiong Tang
7477
*/
7578
class MappingsEndpointTests {
7679

@@ -88,7 +91,7 @@ void servletWebMappings() {
8891
"dispatcherServlets");
8992
assertThat(dispatcherServlets).containsOnlyKeys("dispatcherServlet");
9093
List<DispatcherServletMappingDescription> handlerMappings = dispatcherServlets.get("dispatcherServlet");
91-
assertThat(handlerMappings).hasSize(3);
94+
assertThat(handlerMappings).hasSize(4);
9295
List<ServletRegistrationMappingDescription> servlets = mappings(contextMappings, "servlets");
9396
assertThat(servlets).hasSize(1);
9497
List<FilterRegistrationMappingDescription> filters = mappings(contextMappings, "servletFilters");
@@ -111,7 +114,7 @@ void servletWebMappingsWithPathPatternParser() {
111114
"dispatcherServlets");
112115
assertThat(dispatcherServlets).containsOnlyKeys("dispatcherServlet");
113116
List<DispatcherServletMappingDescription> handlerMappings = dispatcherServlets.get("dispatcherServlet");
114-
assertThat(handlerMappings).hasSize(3);
117+
assertThat(handlerMappings).hasSize(4);
115118
List<ServletRegistrationMappingDescription> servlets = mappings(contextMappings, "servlets");
116119
assertThat(servlets).hasSize(1);
117120
List<FilterRegistrationMappingDescription> filters = mappings(contextMappings, "servletFilters");
@@ -131,9 +134,9 @@ void servletWebMappingsWithAdditionalDispatcherServlets() {
131134
"dispatcherServlets");
132135
assertThat(dispatcherServlets).containsOnlyKeys("dispatcherServlet",
133136
"customDispatcherServletRegistration", "anotherDispatcherServletRegistration");
134-
assertThat(dispatcherServlets.get("dispatcherServlet")).hasSize(3);
135-
assertThat(dispatcherServlets.get("customDispatcherServletRegistration")).hasSize(3);
136-
assertThat(dispatcherServlets.get("anotherDispatcherServletRegistration")).hasSize(3);
137+
assertThat(dispatcherServlets.get("dispatcherServlet")).hasSize(4);
138+
assertThat(dispatcherServlets.get("customDispatcherServletRegistration")).hasSize(4);
139+
assertThat(dispatcherServlets.get("anotherDispatcherServletRegistration")).hasSize(4);
137140
});
138141
}
139142

@@ -248,18 +251,26 @@ DispatcherServlet dispatcherServlet(WebApplicationContext context) throws Servle
248251
return dispatcherServlet;
249252
}
250253

254+
@Bean
255+
org.springframework.web.servlet.function.RouterFunction<org.springframework.web.servlet.function.ServerResponse> routerFunction() {
256+
return RouterFunctions
257+
.route(RequestPredicates.GET("/one"),
258+
(request) -> org.springframework.web.servlet.function.ServerResponse.ok().build())
259+
.andRoute(RequestPredicates.POST("/two"),
260+
(request) -> org.springframework.web.servlet.function.ServerResponse.ok().build());
261+
}
262+
251263
@RequestMapping("/three")
252264
void three() {
253265

254266
}
255267

256268
@Bean
257-
org.springframework.web.servlet.function.RouterFunction<org.springframework.web.servlet.function.ServerResponse> routerFunction() {
258-
return org.springframework.web.servlet.function.RouterFunctions
259-
.route(org.springframework.web.servlet.function.RequestPredicates.GET("/one"),
260-
(request) -> org.springframework.web.servlet.function.ServerResponse.ok().build())
261-
.andRoute(org.springframework.web.servlet.function.RequestPredicates.POST("/two"),
262-
(request) -> org.springframework.web.servlet.function.ServerResponse.ok().build());
269+
org.springframework.web.servlet.function.RouterFunction<org.springframework.web.servlet.function.ServerResponse> routerFunctionWithAttributes() {
270+
return RouterFunctions
271+
.route(RequestPredicates.GET("/four"),
272+
(request) -> org.springframework.web.servlet.function.ServerResponse.ok().build())
273+
.withAttribute("test", "test");
263274
}
264275

265276
}

0 commit comments

Comments
 (0)