From ce0aed216b5cc04fbf52ba7a9007c185593e5625 Mon Sep 17 00:00:00 2001 From: Andreas Grub Date: Wed, 24 Nov 2021 07:47:21 +0100 Subject: [PATCH] Add getter for RequestMappingInfo.BuilderConfiguration This improves support for programmatic registration of mappings to use the same config as that of the RequestMappingHandlerMapping. See gh-27723 --- .../annotation/RequestMappingHandlerMapping.java | 11 +++++++++++ .../annotation/RequestMappingHandlerMappingTests.java | 11 +++++++++++ 2 files changed, 22 insertions(+) diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerMapping.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerMapping.java index 1da7ca1ed8b..6bebaa18df0 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerMapping.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerMapping.java @@ -246,6 +246,17 @@ public class RequestMappingHandlerMapping extends RequestMappingInfoHandlerMappi return this.config.getFileExtensions(); } + /** + * Get the configuration to build {@link RequestMappingInfo} + * instances. This is useful for programmatic registration of + * additional mappings following the same configuration as {@link + * #createRequestMappingInfo(RequestMapping, RequestCondition)}. + * + * @return builder configuration to be supplied into {@link RequestMappingInfo.Builder#options}. + */ + public RequestMappingInfo.BuilderConfiguration getRequestMappingInfoBuilderConfiguration() { + return this.config; + } /** * {@inheritDoc} diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerMappingTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerMappingTests.java index f60e69af0e3..2e6149bc969 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerMappingTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerMappingTests.java @@ -79,6 +79,17 @@ public class RequestMappingHandlerMappingTests { return Stream.of(Arguments.of(mapping1, wac1), Arguments.of(mapping2, wac2)); } + @Test + void getRequestMappingInfoBuilderConfiguration() { + RequestMappingHandlerMapping handlerMapping = new RequestMappingHandlerMapping(); + handlerMapping.setApplicationContext(new StaticWebApplicationContext()); + + RequestMappingInfo.BuilderConfiguration beforeAfterPropertiesSet = handlerMapping.getRequestMappingInfoBuilderConfiguration(); + assertThat(beforeAfterPropertiesSet).isNotNull(); + handlerMapping.afterPropertiesSet(); + RequestMappingInfo.BuilderConfiguration afterPropertiesSet = handlerMapping.getRequestMappingInfoBuilderConfiguration(); + assertThat(afterPropertiesSet).isNotNull().isNotSameAs(beforeAfterPropertiesSet); + } @Test @SuppressWarnings("deprecation")