Ensure that endpoints are created before their web extensions

Closes gh-10140
pull/10168/head
Andy Wilkinson 7 years ago
parent ab82aed96a
commit 9ffbfb0d80

@ -19,6 +19,7 @@ package org.springframework.boot.actuate.autoconfigure;
import org.springframework.beans.factory.SmartInitializingSingleton; import org.springframework.beans.factory.SmartInitializingSingleton;
import org.springframework.boot.actuate.autoconfigure.web.ManagementServerProperties; import org.springframework.boot.actuate.autoconfigure.web.ManagementServerProperties;
import org.springframework.boot.actuate.endpoint.mvc.ManagementServletContext; import org.springframework.boot.actuate.endpoint.mvc.ManagementServletContext;
import org.springframework.boot.autoconfigure.AutoConfigureOrder;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type; import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type;
@ -33,6 +34,7 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.ContextClosedEvent; import org.springframework.context.event.ContextClosedEvent;
import org.springframework.context.support.AbstractApplicationContext; import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.core.Ordered;
import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;
import org.springframework.core.env.PropertySource; import org.springframework.core.env.PropertySource;
@ -51,6 +53,7 @@ import org.springframework.web.context.ConfigurableWebApplicationContext;
* @since 2.0.0 * @since 2.0.0
*/ */
@Configuration @Configuration
@AutoConfigureOrder(Ordered.LOWEST_PRECEDENCE)
public class ManagementContextAutoConfiguration { public class ManagementContextAutoConfiguration {
@Configuration @Configuration

@ -38,14 +38,12 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type; import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type;
import org.springframework.boot.autoconfigure.condition.SearchStrategy;
import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
/** /**
* Configuration for web-specific health endpoints * Configuration for web-specific health endpoints .
* .
* @author Stephane Nicoll * @author Stephane Nicoll
* @since 2.0.0 * @since 2.0.0
*/ */
@ -73,17 +71,18 @@ public class HealthWebEndpointConfiguration {
ReactiveWebHealthConfiguration(ObjectProvider<HealthAggregator> healthAggregator, ReactiveWebHealthConfiguration(ObjectProvider<HealthAggregator> healthAggregator,
ObjectProvider<Map<String, ReactiveHealthIndicator>> reactiveHealthIndicators, ObjectProvider<Map<String, ReactiveHealthIndicator>> reactiveHealthIndicators,
ObjectProvider<Map<String, HealthIndicator>> healthIndicators) { ObjectProvider<Map<String, HealthIndicator>> healthIndicators) {
this.reactiveHealthIndicator = new CompositeReactiveHealthIndicatorFactory().createReactiveHealthIndicator( this.reactiveHealthIndicator = new CompositeReactiveHealthIndicatorFactory()
.createReactiveHealthIndicator(
healthAggregator.getIfAvailable(OrderedHealthAggregator::new), healthAggregator.getIfAvailable(OrderedHealthAggregator::new),
reactiveHealthIndicators.getIfAvailable(Collections::emptyMap), reactiveHealthIndicators
.getIfAvailable(Collections::emptyMap),
healthIndicators.getIfAvailable(Collections::emptyMap)); healthIndicators.getIfAvailable(Collections::emptyMap));
} }
@Bean @Bean
@ConditionalOnMissingBean @ConditionalOnMissingBean
@ConditionalOnEnabledEndpoint @ConditionalOnEnabledEndpoint
@ConditionalOnBean(value = HealthEndpoint.class, search = SearchStrategy.CURRENT) @ConditionalOnBean(HealthEndpoint.class)
public HealthReactiveWebEndpointExtension healthWebEndpointExtension( public HealthReactiveWebEndpointExtension healthWebEndpointExtension(
HealthStatusHttpMapper healthStatusHttpMapper) { HealthStatusHttpMapper healthStatusHttpMapper) {
return new HealthReactiveWebEndpointExtension(this.reactiveHealthIndicator, return new HealthReactiveWebEndpointExtension(this.reactiveHealthIndicator,
@ -93,7 +92,7 @@ public class HealthWebEndpointConfiguration {
@Bean @Bean
@ConditionalOnMissingBean @ConditionalOnMissingBean
@ConditionalOnEnabledEndpoint @ConditionalOnEnabledEndpoint
@ConditionalOnBean(value = StatusEndpoint.class, search = SearchStrategy.CURRENT) @ConditionalOnBean(StatusEndpoint.class)
public StatusReactiveWebEndpointExtension statusWebEndpointExtension( public StatusReactiveWebEndpointExtension statusWebEndpointExtension(
HealthStatusHttpMapper healthStatusHttpMapper) { HealthStatusHttpMapper healthStatusHttpMapper) {
return new StatusReactiveWebEndpointExtension(this.reactiveHealthIndicator, return new StatusReactiveWebEndpointExtension(this.reactiveHealthIndicator,
@ -109,7 +108,7 @@ public class HealthWebEndpointConfiguration {
@Bean @Bean
@ConditionalOnMissingBean @ConditionalOnMissingBean
@ConditionalOnEnabledEndpoint @ConditionalOnEnabledEndpoint
@ConditionalOnBean(value = HealthEndpoint.class, search = SearchStrategy.CURRENT) @ConditionalOnBean(HealthEndpoint.class)
public HealthWebEndpointExtension healthWebEndpointExtension( public HealthWebEndpointExtension healthWebEndpointExtension(
HealthEndpoint delegate, HealthStatusHttpMapper healthStatusHttpMapper) { HealthEndpoint delegate, HealthStatusHttpMapper healthStatusHttpMapper) {
return new HealthWebEndpointExtension(delegate, healthStatusHttpMapper); return new HealthWebEndpointExtension(delegate, healthStatusHttpMapper);
@ -118,7 +117,7 @@ public class HealthWebEndpointConfiguration {
@Bean @Bean
@ConditionalOnMissingBean @ConditionalOnMissingBean
@ConditionalOnEnabledEndpoint @ConditionalOnEnabledEndpoint
@ConditionalOnBean(value = StatusEndpoint.class, search = SearchStrategy.CURRENT) @ConditionalOnBean(StatusEndpoint.class)
public StatusWebEndpointExtension statusWebEndpointExtension( public StatusWebEndpointExtension statusWebEndpointExtension(
StatusEndpoint delegate, HealthStatusHttpMapper healthStatusHttpMapper) { StatusEndpoint delegate, HealthStatusHttpMapper healthStatusHttpMapper) {
return new StatusWebEndpointExtension(delegate, healthStatusHttpMapper); return new StatusWebEndpointExtension(delegate, healthStatusHttpMapper);

@ -0,0 +1,105 @@
/*
* Copyright 2012-2017 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
*
* http://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.endpoint.web;
import org.junit.Test;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.actuate.endpoint.web.HealthReactiveWebEndpointExtension;
import org.springframework.boot.actuate.endpoint.web.HealthWebEndpointExtension;
import org.springframework.boot.actuate.endpoint.web.StatusReactiveWebEndpointExtension;
import org.springframework.boot.actuate.endpoint.web.StatusWebEndpointExtension;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.cassandra.CassandraAutoConfiguration;
import org.springframework.boot.autoconfigure.data.cassandra.CassandraDataAutoConfiguration;
import org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchAutoConfiguration;
import org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchDataAutoConfiguration;
import org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration;
import org.springframework.boot.autoconfigure.data.neo4j.Neo4jDataAutoConfiguration;
import org.springframework.boot.autoconfigure.data.neo4j.Neo4jRepositoriesAutoConfiguration;
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
import org.springframework.boot.autoconfigure.data.redis.RedisRepositoriesAutoConfiguration;
import org.springframework.boot.autoconfigure.data.rest.RepositoryRestMvcAutoConfiguration;
import org.springframework.boot.autoconfigure.data.solr.SolrRepositoriesAutoConfiguration;
import org.springframework.boot.autoconfigure.elasticsearch.jest.JestAutoConfiguration;
import org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration;
import org.springframework.boot.autoconfigure.hazelcast.HazelcastAutoConfiguration;
import org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration;
import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration;
import org.springframework.boot.autoconfigure.solr.SolrAutoConfiguration;
import org.springframework.boot.context.annotation.UserConfigurations;
import org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner;
import org.springframework.boot.test.context.runner.WebApplicationContextRunner;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Integration tests for the auto-configuration of web endpoints.
*
* @author Andy Wilkinson
*/
public class WebEndpointAutoConfigurationIntegrationTests {
@Test
public void healthEndpointWebExtensionIsAutoConfigured() {
servletWebRunner().run((context) -> assertThat(context)
.hasSingleBean(HealthWebEndpointExtension.class));
}
@Test
public void statusEndpointWebExtensionIsAutoConfigured() {
servletWebRunner().run((context) -> assertThat(context)
.hasSingleBean(StatusWebEndpointExtension.class));
}
@Test
public void healthEndpointReactiveWebExtensionIsAutoConfigured() {
reactiveWebRunner().run((context) -> assertThat(context)
.hasSingleBean(HealthReactiveWebEndpointExtension.class));
}
@Test
public void statusEndpointReactiveWebExtensionIsAutoConfigured() {
reactiveWebRunner().run((context) -> assertThat(context)
.hasSingleBean(StatusReactiveWebEndpointExtension.class));
}
private WebApplicationContextRunner servletWebRunner() {
return new WebApplicationContextRunner().withConfiguration(
UserConfigurations.of(WebEndpointTestApplication.class));
}
private ReactiveWebApplicationContextRunner reactiveWebRunner() {
return new ReactiveWebApplicationContextRunner().withConfiguration(
UserConfigurations.of(WebEndpointTestApplication.class));
}
@EnableAutoConfiguration(exclude = { FlywayAutoConfiguration.class,
LiquibaseAutoConfiguration.class, CassandraAutoConfiguration.class,
CassandraDataAutoConfiguration.class, Neo4jDataAutoConfiguration.class,
Neo4jRepositoriesAutoConfiguration.class, MongoAutoConfiguration.class,
RepositoryRestMvcAutoConfiguration.class, HazelcastAutoConfiguration.class,
MongoDataAutoConfiguration.class, ElasticsearchAutoConfiguration.class,
ElasticsearchDataAutoConfiguration.class, JestAutoConfiguration.class,
SolrRepositoriesAutoConfiguration.class, SolrAutoConfiguration.class,
RedisAutoConfiguration.class, RedisRepositoriesAutoConfiguration.class })
@SpringBootConfiguration
public static class WebEndpointTestApplication {
}
}
Loading…
Cancel
Save