From 42195163aeb2d20998d594d75d7e22ee8f766127 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Wed, 4 Jun 2025 13:32:31 +0100 Subject: [PATCH] Move mapping description auto-configuration into appropriate modules --- .../MappingsEndpointAutoConfiguration.java | 96 ------------------- ...ot.autoconfigure.AutoConfiguration.imports | 1 - ...appingsEndpointAutoConfigurationTests.java | 74 -------------- .../MappingsEndpointAutoConfiguration.java | 44 +++++++++ .../web/mappings/package-info.java | 0 ...ot.autoconfigure.AutoConfiguration.imports | 1 + ...appingsEndpointAutoConfigurationTests.java | 49 ++++++++++ .../ServletMappingsAutoConfiguration.java | 54 +++++++++++ .../autoconfigure/mappings/package-info.java | 20 ++++ ...ot.autoconfigure.AutoConfiguration.imports | 1 + ...ServletMappingsAutoConfigurationTests.java | 51 ++++++++++ .../WebFluxMappingsAutoConfiguration.java | 52 ++++++++++ .../autoconfigure/mappings/package-info.java | 20 ++++ ...ot.autoconfigure.AutoConfiguration.imports | 3 +- ...WebFluxMappingsAutoConfigurationTests.java | 57 +++++++++++ .../WebMvcMappingsAutoConfiguration.java | 52 ++++++++++ .../autoconfigure/mappings/package-info.java | 20 ++++ ...ot.autoconfigure.AutoConfiguration.imports | 1 + .../WebMvcMappingsAutoConfigurationTests.java | 57 +++++++++++ 19 files changed, 481 insertions(+), 172 deletions(-) delete mode 100644 spring-boot-project/spring-boot-actuator-autoconfigure-all/src/main/java/org/springframework/boot/actuate/autoconfigure/web/mappings/MappingsEndpointAutoConfiguration.java delete mode 100644 spring-boot-project/spring-boot-actuator-autoconfigure-all/src/test/java/org/springframework/boot/actuate/autoconfigure/web/mappings/MappingsEndpointAutoConfigurationTests.java create mode 100644 spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/mappings/MappingsEndpointAutoConfiguration.java rename spring-boot-project/{spring-boot-actuator-autoconfigure-all => spring-boot-actuator-autoconfigure}/src/main/java/org/springframework/boot/actuate/autoconfigure/web/mappings/package-info.java (100%) create mode 100644 spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/web/mappings/MappingsEndpointAutoConfigurationTests.java create mode 100644 spring-boot-project/spring-boot-servlet/src/main/java/org/springframework/boot/servlet/actuate/autoconfigure/mappings/ServletMappingsAutoConfiguration.java create mode 100644 spring-boot-project/spring-boot-servlet/src/main/java/org/springframework/boot/servlet/actuate/autoconfigure/mappings/package-info.java create mode 100644 spring-boot-project/spring-boot-servlet/src/test/java/org/springframework/boot/servlet/actuate/autoconfigure/mappings/ServletMappingsAutoConfigurationTests.java create mode 100644 spring-boot-project/spring-boot-webflux/src/main/java/org/springframework/boot/webflux/actuate/autoconfigure/mappings/WebFluxMappingsAutoConfiguration.java create mode 100644 spring-boot-project/spring-boot-webflux/src/main/java/org/springframework/boot/webflux/actuate/autoconfigure/mappings/package-info.java create mode 100644 spring-boot-project/spring-boot-webflux/src/test/java/org/springframework/boot/webflux/actuate/autoconfigure/mappings/WebFluxMappingsAutoConfigurationTests.java create mode 100644 spring-boot-project/spring-boot-webmvc/src/main/java/org/springframework/boot/webmvc/actuate/autoconfigure/mappings/WebMvcMappingsAutoConfiguration.java create mode 100644 spring-boot-project/spring-boot-webmvc/src/main/java/org/springframework/boot/webmvc/actuate/autoconfigure/mappings/package-info.java create mode 100644 spring-boot-project/spring-boot-webmvc/src/test/java/org/springframework/boot/webmvc/actuate/autoconfigure/mappings/WebMvcMappingsAutoConfigurationTests.java diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure-all/src/main/java/org/springframework/boot/actuate/autoconfigure/web/mappings/MappingsEndpointAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure-all/src/main/java/org/springframework/boot/actuate/autoconfigure/web/mappings/MappingsEndpointAutoConfiguration.java deleted file mode 100644 index c4d836e021..0000000000 --- a/spring-boot-project/spring-boot-actuator-autoconfigure-all/src/main/java/org/springframework/boot/actuate/autoconfigure/web/mappings/MappingsEndpointAutoConfiguration.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright 2012-2025 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.actuate.autoconfigure.web.mappings; - -import org.springframework.beans.factory.ObjectProvider; -import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnAvailableEndpoint; -import org.springframework.boot.actuate.web.mappings.MappingDescriptionProvider; -import org.springframework.boot.actuate.web.mappings.MappingsEndpoint; -import org.springframework.boot.autoconfigure.AutoConfiguration; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; -import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; -import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; -import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type; -import org.springframework.boot.servlet.actuate.mappings.FiltersMappingDescriptionProvider; -import org.springframework.boot.servlet.actuate.mappings.ServletsMappingDescriptionProvider; -import org.springframework.boot.webflux.actuate.mappings.DispatcherHandlersMappingDescriptionProvider; -import org.springframework.boot.webmvc.actuate.mappings.DispatcherServletsMappingDescriptionProvider; -import org.springframework.context.ApplicationContext; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.web.reactive.DispatcherHandler; -import org.springframework.web.servlet.DispatcherServlet; - -/** - * {@link EnableAutoConfiguration Auto-configuration} for {@link MappingsEndpoint}. - * - * @author Andy Wilkinson - * @since 2.0.0 - */ -@AutoConfiguration -@ConditionalOnAvailableEndpoint(MappingsEndpoint.class) -public class MappingsEndpointAutoConfiguration { - - @Bean - public MappingsEndpoint mappingsEndpoint(ApplicationContext applicationContext, - ObjectProvider descriptionProviders) { - return new MappingsEndpoint(descriptionProviders.orderedStream().toList(), applicationContext); - } - - @Configuration(proxyBeanMethods = false) - @ConditionalOnWebApplication(type = Type.SERVLET) - static class ServletWebConfiguration { - - @Bean - ServletsMappingDescriptionProvider servletMappingDescriptionProvider() { - return new ServletsMappingDescriptionProvider(); - } - - @Bean - FiltersMappingDescriptionProvider filterMappingDescriptionProvider() { - return new FiltersMappingDescriptionProvider(); - } - - @Configuration(proxyBeanMethods = false) - @ConditionalOnClass(DispatcherServlet.class) - @ConditionalOnBean(DispatcherServlet.class) - static class SpringMvcConfiguration { - - @Bean - DispatcherServletsMappingDescriptionProvider dispatcherServletMappingDescriptionProvider() { - return new DispatcherServletsMappingDescriptionProvider(); - } - - } - - } - - @Configuration(proxyBeanMethods = false) - @ConditionalOnWebApplication(type = Type.REACTIVE) - @ConditionalOnClass(DispatcherHandler.class) - @ConditionalOnBean(DispatcherHandler.class) - static class ReactiveWebConfiguration { - - @Bean - DispatcherHandlersMappingDescriptionProvider dispatcherHandlerMappingDescriptionProvider() { - return new DispatcherHandlersMappingDescriptionProvider(); - } - - } - -} diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure-all/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/spring-boot-project/spring-boot-actuator-autoconfigure-all/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports index 390d6b4a6d..c51177ef37 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure-all/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +++ b/spring-boot-project/spring-boot-actuator-autoconfigure-all/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -14,4 +14,3 @@ org.springframework.boot.actuate.autoconfigure.tracing.prometheus.PrometheusExem org.springframework.boot.actuate.autoconfigure.tracing.zipkin.ZipkinTracingAutoConfiguration org.springframework.boot.actuate.autoconfigure.web.exchanges.HttpExchangesAutoConfiguration org.springframework.boot.actuate.autoconfigure.web.exchanges.HttpExchangesEndpointAutoConfiguration -org.springframework.boot.actuate.autoconfigure.web.mappings.MappingsEndpointAutoConfiguration diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure-all/src/test/java/org/springframework/boot/actuate/autoconfigure/web/mappings/MappingsEndpointAutoConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure-all/src/test/java/org/springframework/boot/actuate/autoconfigure/web/mappings/MappingsEndpointAutoConfigurationTests.java deleted file mode 100644 index 8c4e59552b..0000000000 --- a/spring-boot-project/spring-boot-actuator-autoconfigure-all/src/test/java/org/springframework/boot/actuate/autoconfigure/web/mappings/MappingsEndpointAutoConfigurationTests.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright 2012-2025 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.actuate.autoconfigure.web.mappings; - -import org.junit.jupiter.api.Test; - -import org.springframework.boot.actuate.autoconfigure.endpoint.EndpointAutoConfiguration; -import org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointAutoConfiguration; -import org.springframework.boot.actuate.web.mappings.MappingDescriptionProvider; -import org.springframework.boot.actuate.web.mappings.MappingsEndpoint; -import org.springframework.boot.autoconfigure.AutoConfigurations; -import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; -import org.springframework.boot.http.converter.autoconfigure.HttpMessageConvertersAutoConfiguration; -import org.springframework.boot.jackson.autoconfigure.JacksonAutoConfiguration; -import org.springframework.boot.test.context.runner.WebApplicationContextRunner; -import org.springframework.boot.webmvc.actuate.autoconfigure.endpoint.web.WebMvcEndpointManagementContextConfiguration; -import org.springframework.boot.webmvc.autoconfigure.DispatcherServletAutoConfiguration; -import org.springframework.boot.webmvc.autoconfigure.WebMvcAutoConfiguration; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Tests for {@link MappingsEndpointAutoConfiguration}. - * - * @author Andy Wilkinson - */ -class MappingsEndpointAutoConfigurationTests { - - @Test - void whenEndpointIsUnavailableThenEndpointAndDescriptionProvidersAreNotCreated() { - new WebApplicationContextRunner() - .withConfiguration(AutoConfigurations.of(MappingsEndpointAutoConfiguration.class, - JacksonAutoConfiguration.class, HttpMessageConvertersAutoConfiguration.class, - WebMvcAutoConfiguration.class, DispatcherServletAutoConfiguration.class, - EndpointAutoConfiguration.class, WebEndpointAutoConfiguration.class, - WebMvcEndpointManagementContextConfiguration.class, PropertyPlaceholderAutoConfiguration.class)) - .run((context) -> { - assertThat(context).doesNotHaveBean(MappingsEndpoint.class); - assertThat(context).doesNotHaveBean(MappingDescriptionProvider.class); - }); - - } - - @Test - void whenEndpointIsAvailableThenEndpointAndDescriptionProvidersAreCreated() { - new WebApplicationContextRunner() - .withConfiguration(AutoConfigurations.of(MappingsEndpointAutoConfiguration.class, - JacksonAutoConfiguration.class, HttpMessageConvertersAutoConfiguration.class, - WebMvcAutoConfiguration.class, DispatcherServletAutoConfiguration.class, - EndpointAutoConfiguration.class, WebEndpointAutoConfiguration.class, - WebMvcEndpointManagementContextConfiguration.class, PropertyPlaceholderAutoConfiguration.class)) - .withPropertyValues("management.endpoints.web.exposure.include=mappings") - .run((context) -> { - assertThat(context).hasSingleBean(MappingsEndpoint.class); - assertThat(context.getBeansOfType(MappingDescriptionProvider.class)).hasSize(3); - }); - - } - -} diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/mappings/MappingsEndpointAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/mappings/MappingsEndpointAutoConfiguration.java new file mode 100644 index 0000000000..3ffb791475 --- /dev/null +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/mappings/MappingsEndpointAutoConfiguration.java @@ -0,0 +1,44 @@ +/* + * Copyright 2012-2025 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.actuate.autoconfigure.web.mappings; + +import org.springframework.beans.factory.ObjectProvider; +import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnAvailableEndpoint; +import org.springframework.boot.actuate.web.mappings.MappingDescriptionProvider; +import org.springframework.boot.actuate.web.mappings.MappingsEndpoint; +import org.springframework.boot.autoconfigure.AutoConfiguration; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.Bean; + +/** + * {@link EnableAutoConfiguration Auto-configuration} for {@link MappingsEndpoint}. + * + * @author Andy Wilkinson + * @since 2.0.0 + */ +@AutoConfiguration +@ConditionalOnAvailableEndpoint(MappingsEndpoint.class) +public class MappingsEndpointAutoConfiguration { + + @Bean + MappingsEndpoint mappingsEndpoint(ApplicationContext applicationContext, + ObjectProvider descriptionProviders) { + return new MappingsEndpoint(descriptionProviders.orderedStream().toList(), applicationContext); + } + +} diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure-all/src/main/java/org/springframework/boot/actuate/autoconfigure/web/mappings/package-info.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/mappings/package-info.java similarity index 100% rename from spring-boot-project/spring-boot-actuator-autoconfigure-all/src/main/java/org/springframework/boot/actuate/autoconfigure/web/mappings/package-info.java rename to spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/mappings/package-info.java diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports index c9286c2ee9..61d842de22 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -23,4 +23,5 @@ org.springframework.boot.actuate.autoconfigure.sbom.SbomEndpointAutoConfiguratio org.springframework.boot.actuate.autoconfigure.scheduling.ScheduledTasksEndpointAutoConfiguration org.springframework.boot.actuate.autoconfigure.startup.StartupEndpointAutoConfiguration org.springframework.boot.actuate.autoconfigure.system.DiskSpaceHealthContributorAutoConfiguration +org.springframework.boot.actuate.autoconfigure.web.mappings.MappingsEndpointAutoConfiguration org.springframework.boot.actuate.autoconfigure.web.server.ManagementContextAutoConfiguration diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/web/mappings/MappingsEndpointAutoConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/web/mappings/MappingsEndpointAutoConfigurationTests.java new file mode 100644 index 0000000000..910a4e9b49 --- /dev/null +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/web/mappings/MappingsEndpointAutoConfigurationTests.java @@ -0,0 +1,49 @@ +/* + * Copyright 2012-2025 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.actuate.autoconfigure.web.mappings; + +import org.junit.jupiter.api.Test; + +import org.springframework.boot.actuate.web.mappings.MappingsEndpoint; +import org.springframework.boot.autoconfigure.AutoConfigurations; +import org.springframework.boot.test.context.runner.WebApplicationContextRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests for {@link MappingsEndpointAutoConfiguration}. + * + * @author Andy Wilkinson + */ +class MappingsEndpointAutoConfigurationTests { + + @Test + void whenEndpointIsUnavailableThenEndpointIsNotCreated() { + new WebApplicationContextRunner() + .withConfiguration(AutoConfigurations.of(MappingsEndpointAutoConfiguration.class)) + .run((context) -> assertThat(context).doesNotHaveBean(MappingsEndpoint.class)); + } + + @Test + void whenEndpointIsAvailableThenEndpointIsCreated() { + new WebApplicationContextRunner() + .withConfiguration(AutoConfigurations.of(MappingsEndpointAutoConfiguration.class)) + .withPropertyValues("management.endpoints.web.exposure.include=mappings") + .run((context) -> assertThat(context).hasSingleBean(MappingsEndpoint.class)); + } + +} diff --git a/spring-boot-project/spring-boot-servlet/src/main/java/org/springframework/boot/servlet/actuate/autoconfigure/mappings/ServletMappingsAutoConfiguration.java b/spring-boot-project/spring-boot-servlet/src/main/java/org/springframework/boot/servlet/actuate/autoconfigure/mappings/ServletMappingsAutoConfiguration.java new file mode 100644 index 0000000000..e034f985cc --- /dev/null +++ b/spring-boot-project/spring-boot-servlet/src/main/java/org/springframework/boot/servlet/actuate/autoconfigure/mappings/ServletMappingsAutoConfiguration.java @@ -0,0 +1,54 @@ +/* + * Copyright 2012-2025 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.servlet.actuate.autoconfigure.mappings; + +import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnAvailableEndpoint; +import org.springframework.boot.actuate.web.mappings.MappingDescriptionProvider; +import org.springframework.boot.actuate.web.mappings.MappingsEndpoint; +import org.springframework.boot.autoconfigure.AutoConfiguration; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; +import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type; +import org.springframework.boot.servlet.actuate.mappings.FiltersMappingDescriptionProvider; +import org.springframework.boot.servlet.actuate.mappings.ServletsMappingDescriptionProvider; +import org.springframework.context.annotation.Bean; + +/** + * {@link EnableAutoConfiguration Auto-configuration} to describe Servlet-related + * {@link MappingDescriptionProvider mappings}. + * + * @author Andy Wilkinson + * @since 4.0.0 + */ +@AutoConfiguration +@ConditionalOnClass({ ConditionalOnAvailableEndpoint.class, MappingsEndpoint.class }) +@ConditionalOnAvailableEndpoint(MappingsEndpoint.class) +@ConditionalOnWebApplication(type = Type.SERVLET) +public class ServletMappingsAutoConfiguration { + + @Bean + ServletsMappingDescriptionProvider servletMappingDescriptionProvider() { + return new ServletsMappingDescriptionProvider(); + } + + @Bean + FiltersMappingDescriptionProvider filterMappingDescriptionProvider() { + return new FiltersMappingDescriptionProvider(); + } + +} diff --git a/spring-boot-project/spring-boot-servlet/src/main/java/org/springframework/boot/servlet/actuate/autoconfigure/mappings/package-info.java b/spring-boot-project/spring-boot-servlet/src/main/java/org/springframework/boot/servlet/actuate/autoconfigure/mappings/package-info.java new file mode 100644 index 0000000000..6fb1b9d3f4 --- /dev/null +++ b/spring-boot-project/spring-boot-servlet/src/main/java/org/springframework/boot/servlet/actuate/autoconfigure/mappings/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright 2012-2025 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Auto-configuration for Servlet-based integration with Actuator's mappings support. + */ +package org.springframework.boot.servlet.actuate.autoconfigure.mappings; diff --git a/spring-boot-project/spring-boot-servlet/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/spring-boot-project/spring-boot-servlet/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports index b484b51ce0..f496b9b99d 100644 --- a/spring-boot-project/spring-boot-servlet/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +++ b/spring-boot-project/spring-boot-servlet/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -1,2 +1,3 @@ org.springframework.boot.servlet.actuate.autoconfigure.ServletManagementContextAutoConfiguration +org.springframework.boot.servlet.actuate.autoconfigure.mappings.ServletMappingsAutoConfiguration org.springframework.boot.servlet.autoconfigure.MultipartAutoConfiguration diff --git a/spring-boot-project/spring-boot-servlet/src/test/java/org/springframework/boot/servlet/actuate/autoconfigure/mappings/ServletMappingsAutoConfigurationTests.java b/spring-boot-project/spring-boot-servlet/src/test/java/org/springframework/boot/servlet/actuate/autoconfigure/mappings/ServletMappingsAutoConfigurationTests.java new file mode 100644 index 0000000000..18b57b6998 --- /dev/null +++ b/spring-boot-project/spring-boot-servlet/src/test/java/org/springframework/boot/servlet/actuate/autoconfigure/mappings/ServletMappingsAutoConfigurationTests.java @@ -0,0 +1,51 @@ +/* + * Copyright 2012-2025 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.servlet.actuate.autoconfigure.mappings; + +import org.junit.jupiter.api.Test; + +import org.springframework.boot.autoconfigure.AutoConfigurations; +import org.springframework.boot.servlet.actuate.mappings.FiltersMappingDescriptionProvider; +import org.springframework.boot.servlet.actuate.mappings.ServletsMappingDescriptionProvider; +import org.springframework.boot.test.context.runner.WebApplicationContextRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests for {@link ServletMappingsAutoConfiguration}. + * + * @author Andy Wilkinson + */ +class ServletMappingsAutoConfigurationTests { + + private final WebApplicationContextRunner contextRunner = new WebApplicationContextRunner() + .withConfiguration(AutoConfigurations.of(ServletMappingsAutoConfiguration.class)); + + @Test + void whenEndpointIsUnavailableThenDescriptionProvidersAreNotCreated() { + this.contextRunner.run((context) -> assertThat(context).doesNotHaveBean(FiltersMappingDescriptionProvider.class) + .doesNotHaveBean(ServletsMappingDescriptionProvider.class)); + } + + @Test + void whenEndpointIsAvailableThenDescriptionProvidersAreCreated() { + this.contextRunner.withPropertyValues("management.endpoints.web.exposure.include=mappings") + .run((context) -> assertThat(context).hasSingleBean(FiltersMappingDescriptionProvider.class) + .hasSingleBean(ServletsMappingDescriptionProvider.class)); + } + +} diff --git a/spring-boot-project/spring-boot-webflux/src/main/java/org/springframework/boot/webflux/actuate/autoconfigure/mappings/WebFluxMappingsAutoConfiguration.java b/spring-boot-project/spring-boot-webflux/src/main/java/org/springframework/boot/webflux/actuate/autoconfigure/mappings/WebFluxMappingsAutoConfiguration.java new file mode 100644 index 0000000000..3823eb50ca --- /dev/null +++ b/spring-boot-project/spring-boot-webflux/src/main/java/org/springframework/boot/webflux/actuate/autoconfigure/mappings/WebFluxMappingsAutoConfiguration.java @@ -0,0 +1,52 @@ +/* + * Copyright 2012-2025 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.webflux.actuate.autoconfigure.mappings; + +import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnAvailableEndpoint; +import org.springframework.boot.actuate.web.mappings.MappingDescriptionProvider; +import org.springframework.boot.actuate.web.mappings.MappingsEndpoint; +import org.springframework.boot.autoconfigure.AutoConfiguration; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; +import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type; +import org.springframework.boot.webflux.actuate.mappings.DispatcherHandlersMappingDescriptionProvider; +import org.springframework.boot.webflux.autoconfigure.WebFluxAutoConfiguration; +import org.springframework.context.annotation.Bean; +import org.springframework.web.reactive.DispatcherHandler; + +/** + * {@link EnableAutoConfiguration Auto-configuration} to {@link MappingDescriptionProvider + * describe} WebFlux mappings. + * + * @author Andy Wilkinson + * @since 4.0.0 + */ +@AutoConfiguration(after = WebFluxAutoConfiguration.class) +@ConditionalOnClass({ ConditionalOnAvailableEndpoint.class, DispatcherHandler.class, MappingsEndpoint.class }) +@ConditionalOnAvailableEndpoint(MappingsEndpoint.class) +@ConditionalOnBean(DispatcherHandler.class) +@ConditionalOnWebApplication(type = Type.REACTIVE) +public class WebFluxMappingsAutoConfiguration { + + @Bean + DispatcherHandlersMappingDescriptionProvider dispatcherHandlersMappingDescriptionProvider() { + return new DispatcherHandlersMappingDescriptionProvider(); + } + +} diff --git a/spring-boot-project/spring-boot-webflux/src/main/java/org/springframework/boot/webflux/actuate/autoconfigure/mappings/package-info.java b/spring-boot-project/spring-boot-webflux/src/main/java/org/springframework/boot/webflux/actuate/autoconfigure/mappings/package-info.java new file mode 100644 index 0000000000..d1b14e7326 --- /dev/null +++ b/spring-boot-project/spring-boot-webflux/src/main/java/org/springframework/boot/webflux/actuate/autoconfigure/mappings/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright 2012-2025 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Auto-configuration for WebFlux-based integration with Actuator's mappings support. + */ +package org.springframework.boot.webflux.actuate.autoconfigure.mappings; diff --git a/spring-boot-project/spring-boot-webflux/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/spring-boot-project/spring-boot-webflux/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports index d3b358a40d..8f8b489e60 100644 --- a/spring-boot-project/spring-boot-webflux/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +++ b/spring-boot-project/spring-boot-webflux/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -1,7 +1,8 @@ org.springframework.boot.webflux.actuate.autoconfigure.health.WebFluxHealthEndpointExtensionAutoConfiguration +org.springframework.boot.webflux.actuate.autoconfigure.mappings.WebFluxMappingsAutoConfiguration org.springframework.boot.webflux.autoconfigure.HttpHandlerAutoConfiguration org.springframework.boot.webflux.autoconfigure.ReactiveMultipartAutoConfiguration org.springframework.boot.webflux.autoconfigure.WebFluxAutoConfiguration org.springframework.boot.webflux.autoconfigure.WebSessionIdResolverAutoConfiguration org.springframework.boot.webflux.autoconfigure.error.ErrorWebFluxAutoConfiguration -org.springframework.boot.webflux.observation.autoconfigure.WebFluxObservationAutoConfiguration +org.springframework.boot.webflux.observation.autoconfigure.WebFluxObservationAutoConfiguration \ No newline at end of file diff --git a/spring-boot-project/spring-boot-webflux/src/test/java/org/springframework/boot/webflux/actuate/autoconfigure/mappings/WebFluxMappingsAutoConfigurationTests.java b/spring-boot-project/spring-boot-webflux/src/test/java/org/springframework/boot/webflux/actuate/autoconfigure/mappings/WebFluxMappingsAutoConfigurationTests.java new file mode 100644 index 0000000000..257155e18f --- /dev/null +++ b/spring-boot-project/spring-boot-webflux/src/test/java/org/springframework/boot/webflux/actuate/autoconfigure/mappings/WebFluxMappingsAutoConfigurationTests.java @@ -0,0 +1,57 @@ +/* + * Copyright 2012-2025 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.webflux.actuate.autoconfigure.mappings; + +import org.junit.jupiter.api.Test; + +import org.springframework.boot.autoconfigure.AutoConfigurations; +import org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner; +import org.springframework.boot.webflux.actuate.mappings.DispatcherHandlersMappingDescriptionProvider; +import org.springframework.web.reactive.DispatcherHandler; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests for {@link WebFluxMappingsAutoConfiguration}. + * + * @author Andy Wilkinson + */ +class WebFluxMappingsAutoConfigurationTests { + + private final ReactiveWebApplicationContextRunner contextRunner = new ReactiveWebApplicationContextRunner() + .withConfiguration(AutoConfigurations.of(WebFluxMappingsAutoConfiguration.class)); + + @Test + void whenEndpointIsUnavailableThenDescriptionProviderIsNotCreated() { + this.contextRunner.withBean(DispatcherHandler.class) + .run((context) -> assertThat(context).doesNotHaveBean(DispatcherHandlersMappingDescriptionProvider.class)); + } + + @Test + void whenEndpointIsAvailableButThereIsNoDispatcherHandlerThenDescriptionProviderIsNotCreated() { + this.contextRunner.withPropertyValues("management.endpoints.web.exposure.include=mappings") + .run((context) -> assertThat(context).doesNotHaveBean(DispatcherHandlersMappingDescriptionProvider.class)); + } + + @Test + void whenEndpointIsAvailableThenDescriptionProviderIsCreated() { + this.contextRunner.withBean(DispatcherHandler.class) + .withPropertyValues("management.endpoints.web.exposure.include=mappings") + .run((context) -> assertThat(context).hasSingleBean(DispatcherHandlersMappingDescriptionProvider.class)); + } + +} diff --git a/spring-boot-project/spring-boot-webmvc/src/main/java/org/springframework/boot/webmvc/actuate/autoconfigure/mappings/WebMvcMappingsAutoConfiguration.java b/spring-boot-project/spring-boot-webmvc/src/main/java/org/springframework/boot/webmvc/actuate/autoconfigure/mappings/WebMvcMappingsAutoConfiguration.java new file mode 100644 index 0000000000..3ccbfff5dd --- /dev/null +++ b/spring-boot-project/spring-boot-webmvc/src/main/java/org/springframework/boot/webmvc/actuate/autoconfigure/mappings/WebMvcMappingsAutoConfiguration.java @@ -0,0 +1,52 @@ +/* + * Copyright 2012-2025 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.webmvc.actuate.autoconfigure.mappings; + +import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnAvailableEndpoint; +import org.springframework.boot.actuate.web.mappings.MappingDescriptionProvider; +import org.springframework.boot.actuate.web.mappings.MappingsEndpoint; +import org.springframework.boot.autoconfigure.AutoConfiguration; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; +import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type; +import org.springframework.boot.webmvc.actuate.mappings.DispatcherServletsMappingDescriptionProvider; +import org.springframework.boot.webmvc.autoconfigure.DispatcherServletAutoConfiguration; +import org.springframework.context.annotation.Bean; +import org.springframework.web.servlet.DispatcherServlet; + +/** + * {@link EnableAutoConfiguration Auto-configuration} to describe Web MVC + * {@link MappingDescriptionProvider mappings}. + * + * @author Andy Wilkinson + * @since 4.0.0 + */ +@AutoConfiguration(after = DispatcherServletAutoConfiguration.class) +@ConditionalOnClass({ ConditionalOnAvailableEndpoint.class, DispatcherServlet.class, MappingsEndpoint.class }) +@ConditionalOnAvailableEndpoint(MappingsEndpoint.class) +@ConditionalOnBean(DispatcherServlet.class) +@ConditionalOnWebApplication(type = Type.SERVLET) +public class WebMvcMappingsAutoConfiguration { + + @Bean + DispatcherServletsMappingDescriptionProvider dispatcherServletMappingDescriptionProvider() { + return new DispatcherServletsMappingDescriptionProvider(); + } + +} diff --git a/spring-boot-project/spring-boot-webmvc/src/main/java/org/springframework/boot/webmvc/actuate/autoconfigure/mappings/package-info.java b/spring-boot-project/spring-boot-webmvc/src/main/java/org/springframework/boot/webmvc/actuate/autoconfigure/mappings/package-info.java new file mode 100644 index 0000000000..d9943e68b7 --- /dev/null +++ b/spring-boot-project/spring-boot-webmvc/src/main/java/org/springframework/boot/webmvc/actuate/autoconfigure/mappings/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright 2012-2025 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Auto-configuration for Spring MVC-based integration with Actuator's mappings support. + */ +package org.springframework.boot.webmvc.actuate.autoconfigure.mappings; diff --git a/spring-boot-project/spring-boot-webmvc/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/spring-boot-project/spring-boot-webmvc/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports index 7537d9c6c9..63d495a1b5 100644 --- a/spring-boot-project/spring-boot-webmvc/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +++ b/spring-boot-project/spring-boot-webmvc/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -1,4 +1,5 @@ org.springframework.boot.webmvc.actuate.autoconfigure.health.WebMvcHealthEndpointExtensionAutoConfiguration +org.springframework.boot.webmvc.actuate.autoconfigure.mappings.WebMvcMappingsAutoConfiguration org.springframework.boot.webmvc.autoconfigure.DispatcherServletAutoConfiguration org.springframework.boot.webmvc.autoconfigure.WebMvcAutoConfiguration org.springframework.boot.webmvc.autoconfigure.error.ErrorMvcAutoConfiguration diff --git a/spring-boot-project/spring-boot-webmvc/src/test/java/org/springframework/boot/webmvc/actuate/autoconfigure/mappings/WebMvcMappingsAutoConfigurationTests.java b/spring-boot-project/spring-boot-webmvc/src/test/java/org/springframework/boot/webmvc/actuate/autoconfigure/mappings/WebMvcMappingsAutoConfigurationTests.java new file mode 100644 index 0000000000..42fc2d72b9 --- /dev/null +++ b/spring-boot-project/spring-boot-webmvc/src/test/java/org/springframework/boot/webmvc/actuate/autoconfigure/mappings/WebMvcMappingsAutoConfigurationTests.java @@ -0,0 +1,57 @@ +/* + * Copyright 2012-2025 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.webmvc.actuate.autoconfigure.mappings; + +import org.junit.jupiter.api.Test; + +import org.springframework.boot.autoconfigure.AutoConfigurations; +import org.springframework.boot.test.context.runner.WebApplicationContextRunner; +import org.springframework.boot.webmvc.actuate.mappings.DispatcherServletsMappingDescriptionProvider; +import org.springframework.web.servlet.DispatcherServlet; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests for {@link WebMvcMappingsAutoConfiguration}. + * + * @author Andy Wilkinson + */ +class WebMvcMappingsAutoConfigurationTests { + + private final WebApplicationContextRunner contextRunner = new WebApplicationContextRunner() + .withConfiguration(AutoConfigurations.of(WebMvcMappingsAutoConfiguration.class)); + + @Test + void whenEndpointIsUnavailableThenDescriptionProviderIsNotCreated() { + this.contextRunner.withBean(DispatcherServlet.class) + .run((context) -> assertThat(context).doesNotHaveBean(DispatcherServletsMappingDescriptionProvider.class)); + } + + @Test + void whenEndpointIsAvailableButThereIsNoDispatcherServletThenDescriptionProviderIsNotCreated() { + this.contextRunner.withPropertyValues("management.endpoints.web.exposure.include=mappings") + .run((context) -> assertThat(context).doesNotHaveBean(DispatcherServletsMappingDescriptionProvider.class)); + } + + @Test + void whenEndpointIsAvailableThenDescriptionProviderIsCreated() { + this.contextRunner.withBean(DispatcherServlet.class) + .withPropertyValues("management.endpoints.web.exposure.include=mappings") + .run((context) -> assertThat(context).hasSingleBean(DispatcherServletsMappingDescriptionProvider.class)); + } + +}