Create a report based on Boot's autoconfiguration decisions
- Gather autoconfiguration conditional decisiions (true and false) - Provide an actuator endpoint as one means to read the report - Define @EnableAutConfigurationReport annotation to turn this feature on - Tidy up autoconfig report a bit and log it if --debug=true
This commit is contained in:
committed by
Dave Syer
parent
089233e472
commit
b63016d8fc
@@ -22,6 +22,7 @@ import java.util.Properties;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.actuate.endpoint.AutoConfigurationReportEndpoint;
|
||||
import org.springframework.boot.actuate.endpoint.BeansEndpoint;
|
||||
import org.springframework.boot.actuate.endpoint.DumpEndpoint;
|
||||
import org.springframework.boot.actuate.endpoint.Endpoint;
|
||||
@@ -41,7 +42,9 @@ import org.springframework.boot.actuate.trace.InMemoryTraceRepository;
|
||||
import org.springframework.boot.actuate.trace.TraceRepository;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.report.AutoConfigurationReport;
|
||||
import org.springframework.boot.bind.PropertiesConfigurationFactory;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -54,9 +57,10 @@ import org.springframework.http.MediaType;
|
||||
/**
|
||||
* {@link EnableAutoConfiguration Auto-configuration} for common management
|
||||
* {@link Endpoint}s.
|
||||
*
|
||||
*
|
||||
* @author Dave Syer
|
||||
* @author Phillip Webb
|
||||
* @author Greg Turnquist
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnClass(MediaType.class)
|
||||
@@ -128,6 +132,13 @@ public class EndpointAutoConfiguration {
|
||||
return new DumpEndpoint();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnBean(AutoConfigurationReport.class)
|
||||
@ConditionalOnMissingBean
|
||||
public AutoConfigurationReportEndpoint autoConfigurationAuditEndpoint() {
|
||||
return new AutoConfigurationReportEndpoint();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public ShutdownEndpoint shutdownEndpoint() {
|
||||
@@ -139,7 +150,6 @@ public class EndpointAutoConfiguration {
|
||||
|
||||
@Autowired
|
||||
private ConfigurableEnvironment environment = new StandardEnvironment();
|
||||
|
||||
@Value("${spring.git.properties:classpath:git.properties}")
|
||||
private Resource gitProperties;
|
||||
|
||||
|
||||
@@ -32,6 +32,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
|
||||
import org.springframework.boot.autoconfigure.condition.Outcome;
|
||||
import org.springframework.boot.autoconfigure.condition.SpringBootCondition;
|
||||
import org.springframework.boot.autoconfigure.thymeleaf.ThymeleafAutoConfiguration.DefaultTemplateResolverConfiguration;
|
||||
import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration;
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright 2012-2013 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.endpoint;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.report.AutoConfigurationReport;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
/**
|
||||
* Endpoint to serve up autoconfiguration report if actuator is on the classpath.
|
||||
*
|
||||
* @author Greg Turnquist
|
||||
*/
|
||||
@ConfigurationProperties(name = "endpoints.autoconfigurationreport", ignoreUnknownFields = false)
|
||||
public class AutoConfigurationReportEndpoint extends AbstractEndpoint<AutoConfigurationReport> {
|
||||
|
||||
@Autowired
|
||||
private AutoConfigurationReport autoConfigurationReport;
|
||||
|
||||
public AutoConfigurationReportEndpoint() {
|
||||
super("/autoconfigurationreport");
|
||||
}
|
||||
|
||||
@Override
|
||||
public AutoConfigurationReport invoke() {
|
||||
return this.autoConfigurationReport;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -18,8 +18,9 @@ package org.springframework.boot.actuate.autoconfigure;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||
import org.springframework.boot.TestUtils;
|
||||
import org.springframework.boot.actuate.autoconfigure.EndpointAutoConfiguration;
|
||||
import org.springframework.boot.actuate.endpoint.AutoConfigurationReportEndpoint;
|
||||
import org.springframework.boot.actuate.endpoint.BeansEndpoint;
|
||||
import org.springframework.boot.actuate.endpoint.DumpEndpoint;
|
||||
import org.springframework.boot.actuate.endpoint.EnvironmentEndpoint;
|
||||
@@ -28,6 +29,7 @@ import org.springframework.boot.actuate.endpoint.InfoEndpoint;
|
||||
import org.springframework.boot.actuate.endpoint.MetricsEndpoint;
|
||||
import org.springframework.boot.actuate.endpoint.ShutdownEndpoint;
|
||||
import org.springframework.boot.actuate.endpoint.TraceEndpoint;
|
||||
import org.springframework.boot.autoconfigure.report.AutoConfigurationReportCreator;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
@@ -39,6 +41,7 @@ import static org.junit.Assert.assertNull;
|
||||
*
|
||||
* @author Dave Syer
|
||||
* @author Phillip Webb
|
||||
* @author Greg Turnquist
|
||||
*/
|
||||
public class EndpointAutoConfigurationTests {
|
||||
|
||||
@@ -63,6 +66,20 @@ public class EndpointAutoConfigurationTests {
|
||||
assertNotNull(this.context.getBean(TraceEndpoint.class));
|
||||
}
|
||||
|
||||
@Test(expected = NoSuchBeanDefinitionException.class)
|
||||
public void noAutoConfigurationAuditEndpointByDefault() {
|
||||
this.context.getBean(AutoConfigurationReportEndpoint.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void autoconfigurationAuditEndpoints() {
|
||||
this.context = new AnnotationConfigApplicationContext();
|
||||
this.context.register(EndpointAutoConfiguration.class, AutoConfigurationReportCreator.class);
|
||||
this.context.refresh();
|
||||
assertNotNull(this.context.getBean(AutoConfigurationReportEndpoint.class));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testInfoEndpointConfiguration() throws Exception {
|
||||
this.context = new AnnotationConfigApplicationContext();
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright 2012-2013 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.endpoint;
|
||||
|
||||
import org.springframework.boot.autoconfigure.report.EnableAutoConfigurationReport;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* Tests for {@link AutoConfigurationReportEndpoint}.
|
||||
*
|
||||
* @author Greg Turnquist
|
||||
*/
|
||||
public class AutoConfigurationReportEndpointTests extends AbstractEndpointTests<AutoConfigurationReportEndpoint> {
|
||||
|
||||
public AutoConfigurationReportEndpointTests() {
|
||||
super(Config.class, AutoConfigurationReportEndpoint.class,
|
||||
"/autoconfigurationreport", true, "endpoints.autoconfigurationreport");
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@EnableConfigurationProperties
|
||||
@EnableAutoConfigurationReport
|
||||
public static class Config {
|
||||
|
||||
@Bean
|
||||
public AutoConfigurationReportEndpoint endpoint() {
|
||||
return new AutoConfigurationReportEndpoint();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user