Move mapping description auto-configuration into appropriate modules

Issue: 46071
This commit is contained in:
Andy Wilkinson 2025-06-04 13:32:31 +01:00 committed by Phillip Webb
parent d75885c092
commit 8ae180024c
19 changed files with 481 additions and 172 deletions

View File

@ -1,96 +0,0 @@
/*
* Copyright 2012-present 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<MappingDescriptionProvider> 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();
}
}
}

View File

@ -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

View File

@ -1,74 +0,0 @@
/*
* Copyright 2012-present 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);
});
}
}

View File

@ -0,0 +1,44 @@
/*
* Copyright 2012-present 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<MappingDescriptionProvider> descriptionProviders) {
return new MappingsEndpoint(descriptionProviders.orderedStream().toList(), applicationContext);
}
}

View File

@ -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

View File

@ -0,0 +1,49 @@
/*
* Copyright 2012-present 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));
}
}

View File

@ -0,0 +1,54 @@
/*
* Copyright 2012-present 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();
}
}

View File

@ -0,0 +1,20 @@
/*
* Copyright 2012-present 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;

View File

@ -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

View File

@ -0,0 +1,51 @@
/*
* Copyright 2012-present 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));
}
}

View File

@ -0,0 +1,52 @@
/*
* Copyright 2012-present 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();
}
}

View File

@ -0,0 +1,20 @@
/*
* Copyright 2012-present 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;

View File

@ -1,4 +1,5 @@
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

View File

@ -0,0 +1,57 @@
/*
* Copyright 2012-present 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));
}
}

View File

@ -0,0 +1,52 @@
/*
* Copyright 2012-present 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();
}
}

View File

@ -0,0 +1,20 @@
/*
* Copyright 2012-present 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;

View File

@ -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

View File

@ -0,0 +1,57 @@
/*
* Copyright 2012-present 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));
}
}