diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/audit/AuditEventsEndpointAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/audit/AuditEventsEndpointAutoConfiguration.java index 6801dba405..58cf651327 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/audit/AuditEventsEndpointAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/audit/AuditEventsEndpointAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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. @@ -37,12 +37,12 @@ import org.springframework.context.annotation.Configuration; */ @Configuration @AutoConfigureAfter(AuditAutoConfiguration.class) +@ConditionalOnEnabledEndpoint(endpoint = AuditEventsEndpoint.class) public class AuditEventsEndpointAutoConfiguration { @Bean @ConditionalOnMissingBean @ConditionalOnBean(AuditEventRepository.class) - @ConditionalOnEnabledEndpoint public AuditEventsEndpoint auditEventsEndpoint( AuditEventRepository auditEventRepository) { return new AuditEventsEndpoint(auditEventRepository); diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/beans/BeansEndpointAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/beans/BeansEndpointAutoConfiguration.java index 27cca0c549..77ec2a731c 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/beans/BeansEndpointAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/beans/BeansEndpointAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2019 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. @@ -31,11 +31,11 @@ import org.springframework.context.annotation.Configuration; * @since 2.0.0 */ @Configuration +@ConditionalOnEnabledEndpoint(endpoint = BeansEndpoint.class) public class BeansEndpointAutoConfiguration { @Bean @ConditionalOnMissingBean - @ConditionalOnEnabledEndpoint public BeansEndpoint beansEndpoint( ConfigurableApplicationContext applicationContext) { return new BeansEndpoint(applicationContext); diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cache/CachesEndpointAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cache/CachesEndpointAutoConfiguration.java index 6137925f78..3214d7452c 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cache/CachesEndpointAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cache/CachesEndpointAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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. @@ -42,12 +42,12 @@ import org.springframework.context.annotation.Configuration; */ @Configuration @ConditionalOnClass(CacheManager.class) +@ConditionalOnEnabledEndpoint(endpoint = CachesEndpoint.class) @AutoConfigureAfter(CacheAutoConfiguration.class) public class CachesEndpointAutoConfiguration { @Bean @ConditionalOnMissingBean - @ConditionalOnEnabledEndpoint public CachesEndpoint cachesEndpoint( ObjectProvider> cacheManagers) { return new CachesEndpoint(cacheManagers.getIfAvailable(LinkedHashMap::new)); @@ -55,7 +55,6 @@ public class CachesEndpointAutoConfiguration { @Bean @ConditionalOnMissingBean - @ConditionalOnEnabledEndpoint @ConditionalOnBean(CachesEndpoint.class) public CachesEndpointWebExtension cachesEndpointWebExtension( CachesEndpoint cachesEndpoint) { diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/condition/ConditionsReportEndpointAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/condition/ConditionsReportEndpointAutoConfiguration.java index 52ce19a106..5b65080e72 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/condition/ConditionsReportEndpointAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/condition/ConditionsReportEndpointAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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. @@ -32,11 +32,11 @@ import org.springframework.context.annotation.Configuration; * @since 2.0.0 */ @Configuration +@ConditionalOnEnabledEndpoint(endpoint = ConditionsReportEndpoint.class) public class ConditionsReportEndpointAutoConfiguration { @Bean @ConditionalOnMissingBean(search = SearchStrategy.CURRENT) - @ConditionalOnEnabledEndpoint public ConditionsReportEndpoint conditionsReportEndpoint( ConfigurableApplicationContext context) { return new ConditionsReportEndpoint(context); diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/context/ShutdownEndpointAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/context/ShutdownEndpointAutoConfiguration.java index c24a3d02b0..08813fdfb9 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/context/ShutdownEndpointAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/context/ShutdownEndpointAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2019 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. @@ -30,11 +30,11 @@ import org.springframework.context.annotation.Configuration; * @since 2.0.0 */ @Configuration +@ConditionalOnEnabledEndpoint(endpoint = ShutdownEndpoint.class) public class ShutdownEndpointAutoConfiguration { @Bean @ConditionalOnMissingBean - @ConditionalOnEnabledEndpoint public ShutdownEndpoint shutdownEndpoint() { return new ShutdownEndpoint(); } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/context/properties/ConfigurationPropertiesReportEndpointAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/context/properties/ConfigurationPropertiesReportEndpointAutoConfiguration.java index 416cd0be9b..d157b4720f 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/context/properties/ConfigurationPropertiesReportEndpointAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/context/properties/ConfigurationPropertiesReportEndpointAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2019 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. @@ -33,6 +33,7 @@ import org.springframework.context.annotation.Configuration; * @since 2.0.0 */ @Configuration +@ConditionalOnEnabledEndpoint(endpoint = ConfigurationPropertiesReportEndpoint.class) @EnableConfigurationProperties(ConfigurationPropertiesReportEndpointProperties.class) public class ConfigurationPropertiesReportEndpointAutoConfiguration { @@ -45,7 +46,6 @@ public class ConfigurationPropertiesReportEndpointAutoConfiguration { @Bean @ConditionalOnMissingBean - @ConditionalOnEnabledEndpoint public ConfigurationPropertiesReportEndpoint configurationPropertiesReportEndpoint() { ConfigurationPropertiesReportEndpoint endpoint = new ConfigurationPropertiesReportEndpoint(); String[] keysToSanitize = this.properties.getKeysToSanitize(); diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/condition/ConditionalOnEnabledEndpoint.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/condition/ConditionalOnEnabledEndpoint.java index f55fb15443..0c2f40f2b3 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/condition/ConditionalOnEnabledEndpoint.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/condition/ConditionalOnEnabledEndpoint.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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. @@ -92,7 +92,7 @@ import org.springframework.core.env.Environment; * @see Endpoint */ @Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.METHOD) +@Target({ ElementType.METHOD, ElementType.TYPE }) @Documented @Conditional(OnEnabledEndpointCondition.class) public @interface ConditionalOnEnabledEndpoint { diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/condition/OnEnabledEndpointCondition.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/condition/OnEnabledEndpointCondition.java index 61bed1d9f0..953c93a22a 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/condition/OnEnabledEndpointCondition.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/condition/OnEnabledEndpointCondition.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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. @@ -90,15 +90,11 @@ class OnEnabledEndpointCondition extends SpringBootCondition { private AnnotationAttributes getEndpointAttributes(ConditionContext context, AnnotatedTypeMetadata metadata) { - Assert.state( - metadata instanceof MethodMetadata - && metadata.isAnnotated(Bean.class.getName()), - "OnEnabledEndpointCondition may only be used on @Bean methods"); - Class endpointType = getEndpointType(context, (MethodMetadata) metadata); - return getEndpointAttributes(endpointType); + return getEndpointAttributes(getEndpointType(context, metadata)); } - private Class getEndpointType(ConditionContext context, MethodMetadata metadata) { + private Class getEndpointType(ConditionContext context, + AnnotatedTypeMetadata metadata) { Map attributes = metadata .getAnnotationAttributes(ConditionalOnEnabledEndpoint.class.getName()); if (attributes != null && attributes.containsKey("endpoint")) { @@ -107,15 +103,19 @@ class OnEnabledEndpointCondition extends SpringBootCondition { return target; } } - // We should be safe to load at this point since we are in the REGISTER_BEAN phase + Assert.state( + metadata instanceof MethodMetadata + && metadata.isAnnotated(Bean.class.getName()), + "OnEnabledEndpointCondition must be used on @Bean methods when the endpoint is not specified"); + MethodMetadata methodMetadata = (MethodMetadata) metadata; try { - return ClassUtils.forName(metadata.getReturnTypeName(), + return ClassUtils.forName(methodMetadata.getReturnTypeName(), context.getClassLoader()); } catch (Throwable ex) { throw new IllegalStateException("Failed to extract endpoint id for " - + metadata.getDeclaringClassName() + "." + metadata.getMethodName(), - ex); + + methodMetadata.getDeclaringClassName() + "." + + methodMetadata.getMethodName(), ex); } } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/env/EnvironmentEndpointAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/env/EnvironmentEndpointAutoConfiguration.java index 6aa3acf70b..b6634c403e 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/env/EnvironmentEndpointAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/env/EnvironmentEndpointAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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. @@ -35,6 +35,7 @@ import org.springframework.core.env.Environment; * @since 2.0.0 */ @Configuration +@ConditionalOnEnabledEndpoint(endpoint = EnvironmentEndpoint.class) @EnableConfigurationProperties(EnvironmentEndpointProperties.class) public class EnvironmentEndpointAutoConfiguration { @@ -47,7 +48,6 @@ public class EnvironmentEndpointAutoConfiguration { @Bean @ConditionalOnMissingBean - @ConditionalOnEnabledEndpoint public EnvironmentEndpoint environmentEndpoint(Environment environment) { EnvironmentEndpoint endpoint = new EnvironmentEndpoint(environment); String[] keysToSanitize = this.properties.getKeysToSanitize(); @@ -59,7 +59,6 @@ public class EnvironmentEndpointAutoConfiguration { @Bean @ConditionalOnMissingBean - @ConditionalOnEnabledEndpoint @ConditionalOnBean(EnvironmentEndpoint.class) public EnvironmentEndpointWebExtension environmentEndpointWebExtension( EnvironmentEndpoint environmentEndpoint) { diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/flyway/FlywayEndpointAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/flyway/FlywayEndpointAutoConfiguration.java index 609117746f..8987a5df37 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/flyway/FlywayEndpointAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/flyway/FlywayEndpointAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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. @@ -38,13 +38,13 @@ import org.springframework.context.annotation.Configuration; */ @Configuration @ConditionalOnClass(Flyway.class) +@ConditionalOnEnabledEndpoint(endpoint = FlywayEndpoint.class) @AutoConfigureAfter(FlywayAutoConfiguration.class) public class FlywayEndpointAutoConfiguration { @Bean @ConditionalOnBean(Flyway.class) @ConditionalOnMissingBean - @ConditionalOnEnabledEndpoint public FlywayEndpoint flywayEndpoint(ApplicationContext context) { return new FlywayEndpoint(context); } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/HealthEndpointConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/HealthEndpointConfiguration.java index 9bb7af2fee..732d352300 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/HealthEndpointConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/HealthEndpointConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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. @@ -33,11 +33,11 @@ import org.springframework.context.annotation.Configuration; */ @Configuration @ConditionalOnSingleCandidate(HealthIndicatorRegistry.class) +@ConditionalOnEnabledEndpoint(endpoint = HealthEndpoint.class) class HealthEndpointConfiguration { @Bean @ConditionalOnMissingBean - @ConditionalOnEnabledEndpoint public HealthEndpoint healthEndpoint(HealthAggregator healthAggregator, HealthIndicatorRegistry registry) { return new HealthEndpoint( diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/HealthEndpointWebExtensionConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/HealthEndpointWebExtensionConfiguration.java index e140ac2e74..1c9d625d83 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/HealthEndpointWebExtensionConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/HealthEndpointWebExtensionConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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. @@ -69,6 +69,7 @@ class HealthEndpointWebExtensionConfiguration { @Configuration @ConditionalOnWebApplication(type = Type.REACTIVE) @ConditionalOnSingleCandidate(ReactiveHealthIndicatorRegistry.class) + @ConditionalOnEnabledEndpoint(endpoint = HealthEndpoint.class) static class ReactiveWebHealthConfiguration { private final ReactiveHealthIndicator reactiveHealthIndicator; @@ -82,7 +83,6 @@ class HealthEndpointWebExtensionConfiguration { @Bean @ConditionalOnMissingBean - @ConditionalOnEnabledEndpoint @ConditionalOnBean(HealthEndpoint.class) public ReactiveHealthEndpointWebExtension reactiveHealthEndpointWebExtension( HealthWebEndpointResponseMapper responseMapper) { @@ -94,11 +94,11 @@ class HealthEndpointWebExtensionConfiguration { @Configuration @ConditionalOnWebApplication(type = Type.SERVLET) + @ConditionalOnEnabledEndpoint(endpoint = HealthEndpoint.class) static class ServletWebHealthConfiguration { @Bean @ConditionalOnMissingBean - @ConditionalOnEnabledEndpoint @ConditionalOnBean(HealthEndpoint.class) public HealthEndpointWebExtension healthEndpointWebExtension( HealthEndpoint healthEndpoint, diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/info/InfoEndpointAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/info/InfoEndpointAutoConfiguration.java index 33ec176115..1bee4a6917 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/info/InfoEndpointAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/info/InfoEndpointAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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. @@ -35,12 +35,12 @@ import org.springframework.context.annotation.Configuration; * @since 2.0.0 */ @Configuration +@ConditionalOnEnabledEndpoint(endpoint = InfoEndpoint.class) @AutoConfigureAfter(InfoContributorAutoConfiguration.class) public class InfoEndpointAutoConfiguration { @Bean @ConditionalOnMissingBean - @ConditionalOnEnabledEndpoint public InfoEndpoint infoEndpoint(ObjectProvider infoContributors) { return new InfoEndpoint( infoContributors.orderedStream().collect(Collectors.toList())); diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/integration/IntegrationGraphEndpointAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/integration/IntegrationGraphEndpointAutoConfiguration.java index 4136ba13a6..977fe0d741 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/integration/IntegrationGraphEndpointAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/integration/IntegrationGraphEndpointAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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. @@ -40,12 +40,12 @@ import org.springframework.integration.graph.IntegrationGraphServer; @Configuration @ConditionalOnClass(IntegrationGraphServer.class) @ConditionalOnBean(IntegrationConfigurationBeanFactoryPostProcessor.class) +@ConditionalOnEnabledEndpoint(endpoint = IntegrationGraphEndpoint.class) @AutoConfigureAfter(IntegrationAutoConfiguration.class) public class IntegrationGraphEndpointAutoConfiguration { @Bean @ConditionalOnMissingBean - @ConditionalOnEnabledEndpoint public IntegrationGraphEndpoint integrationGraphEndpoint( IntegrationGraphServer integrationGraphServer) { return new IntegrationGraphEndpoint(integrationGraphServer); @@ -53,7 +53,6 @@ public class IntegrationGraphEndpointAutoConfiguration { @Bean @ConditionalOnMissingBean - @ConditionalOnEnabledEndpoint(endpoint = IntegrationGraphEndpoint.class) public IntegrationGraphServer integrationGraphServer() { return new IntegrationGraphServer(); } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/jolokia/JolokiaEndpointAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/jolokia/JolokiaEndpointAutoConfiguration.java index cb42ebd6df..2743d36b3f 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/jolokia/JolokiaEndpointAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/jolokia/JolokiaEndpointAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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. @@ -36,11 +36,11 @@ import org.springframework.context.annotation.Configuration; @Configuration @ConditionalOnWebApplication(type = Type.SERVLET) @ConditionalOnClass(AgentServlet.class) +@ConditionalOnEnabledEndpoint(endpoint = JolokiaEndpoint.class) @EnableConfigurationProperties(JolokiaProperties.class) public class JolokiaEndpointAutoConfiguration { @Bean - @ConditionalOnEnabledEndpoint public JolokiaEndpoint jolokiaEndpoint(JolokiaProperties properties) { return new JolokiaEndpoint(properties.getConfig()); } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/liquibase/LiquibaseEndpointAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/liquibase/LiquibaseEndpointAutoConfiguration.java index d4a9db90a9..6c1507aa75 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/liquibase/LiquibaseEndpointAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/liquibase/LiquibaseEndpointAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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. @@ -41,20 +41,19 @@ import org.springframework.context.annotation.Configuration; */ @Configuration @ConditionalOnClass(SpringLiquibase.class) +@ConditionalOnEnabledEndpoint(endpoint = LiquibaseEndpoint.class) @AutoConfigureAfter(LiquibaseAutoConfiguration.class) public class LiquibaseEndpointAutoConfiguration { @Bean @ConditionalOnBean(SpringLiquibase.class) @ConditionalOnMissingBean - @ConditionalOnEnabledEndpoint public LiquibaseEndpoint liquibaseEndpoint(ApplicationContext context) { return new LiquibaseEndpoint(context); } @Bean @ConditionalOnBean(SpringLiquibase.class) - @ConditionalOnEnabledEndpoint(endpoint = LiquibaseEndpoint.class) public static BeanPostProcessor preventDataSourceCloseBeanPostProcessor() { return new BeanPostProcessor() { diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/logging/LoggersEndpointAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/logging/LoggersEndpointAutoConfiguration.java index 1cfb4dd0ed..643cdf2566 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/logging/LoggersEndpointAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/logging/LoggersEndpointAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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. @@ -38,13 +38,13 @@ import org.springframework.core.type.AnnotatedTypeMetadata; * @since 2.0.0 */ @Configuration +@ConditionalOnEnabledEndpoint(endpoint = LoggersEndpoint.class) public class LoggersEndpointAutoConfiguration { @Bean @ConditionalOnBean(LoggingSystem.class) @Conditional(OnEnabledLoggingSystemCondition.class) @ConditionalOnMissingBean - @ConditionalOnEnabledEndpoint public LoggersEndpoint loggersEndpoint(LoggingSystem loggingSystem) { return new LoggersEndpoint(loggingSystem); } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/management/HeapDumpWebEndpointAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/management/HeapDumpWebEndpointAutoConfiguration.java index 3e48cae1a4..543cabd36e 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/management/HeapDumpWebEndpointAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/management/HeapDumpWebEndpointAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2019 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. @@ -30,11 +30,11 @@ import org.springframework.context.annotation.Configuration; * @since 2.0.0 */ @Configuration +@ConditionalOnEnabledEndpoint(endpoint = HeapDumpWebEndpoint.class) public class HeapDumpWebEndpointAutoConfiguration { @Bean @ConditionalOnMissingBean - @ConditionalOnEnabledEndpoint public HeapDumpWebEndpoint heapDumpWebEndpoint() { return new HeapDumpWebEndpoint(); } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/management/ThreadDumpEndpointAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/management/ThreadDumpEndpointAutoConfiguration.java index 75628f543e..0706415bae 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/management/ThreadDumpEndpointAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/management/ThreadDumpEndpointAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2019 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. @@ -30,11 +30,11 @@ import org.springframework.context.annotation.Configuration; * @since 2.0.0 */ @Configuration +@ConditionalOnEnabledEndpoint(endpoint = ThreadDumpEndpoint.class) public class ThreadDumpEndpointAutoConfiguration { @Bean @ConditionalOnMissingBean - @ConditionalOnEnabledEndpoint public ThreadDumpEndpoint dumpEndpoint() { return new ThreadDumpEndpoint(); } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/MetricsEndpointAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/MetricsEndpointAutoConfiguration.java index 259754855b..4c8d77cb84 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/MetricsEndpointAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/MetricsEndpointAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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. @@ -37,6 +37,7 @@ import org.springframework.context.annotation.Configuration; */ @Configuration @ConditionalOnClass(Timed.class) +@ConditionalOnEnabledEndpoint(endpoint = MetricsEndpoint.class) @AutoConfigureAfter({ MetricsAutoConfiguration.class, CompositeMeterRegistryAutoConfiguration.class }) public class MetricsEndpointAutoConfiguration { @@ -44,7 +45,6 @@ public class MetricsEndpointAutoConfiguration { @Bean @ConditionalOnBean(MeterRegistry.class) @ConditionalOnMissingBean - @ConditionalOnEnabledEndpoint public MetricsEndpoint metricsEndpoint(MeterRegistry registry) { return new MetricsEndpoint(registry); } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/prometheus/PrometheusMetricsExportAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/prometheus/PrometheusMetricsExportAutoConfiguration.java index c4454894ba..7067404142 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/prometheus/PrometheusMetricsExportAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/prometheus/PrometheusMetricsExportAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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. @@ -82,10 +82,10 @@ public class PrometheusMetricsExportAutoConfiguration { } @Configuration + @ConditionalOnEnabledEndpoint(endpoint = PrometheusScrapeEndpoint.class) public static class PrometheusScrapeEndpointConfiguration { @Bean - @ConditionalOnEnabledEndpoint @ConditionalOnMissingBean public PrometheusScrapeEndpoint prometheusEndpoint( CollectorRegistry collectorRegistry) { diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/scheduling/ScheduledTasksEndpointAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/scheduling/ScheduledTasksEndpointAutoConfiguration.java index e2ec1d5489..cb3c399519 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/scheduling/ScheduledTasksEndpointAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/scheduling/ScheduledTasksEndpointAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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. @@ -34,11 +34,11 @@ import org.springframework.scheduling.config.ScheduledTaskHolder; * @since 2.0.0 */ @Configuration +@ConditionalOnEnabledEndpoint(endpoint = ScheduledTasksEndpoint.class) public class ScheduledTasksEndpointAutoConfiguration { @Bean @ConditionalOnMissingBean - @ConditionalOnEnabledEndpoint public ScheduledTasksEndpoint scheduledTasksEndpoint( ObjectProvider holders) { return new ScheduledTasksEndpoint( diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/session/SessionsEndpointAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/session/SessionsEndpointAutoConfiguration.java index eba7fd2f30..d6f9300cde 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/session/SessionsEndpointAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/session/SessionsEndpointAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2019 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. @@ -37,13 +37,13 @@ import org.springframework.session.Session; */ @Configuration @ConditionalOnClass(FindByIndexNameSessionRepository.class) +@ConditionalOnEnabledEndpoint(endpoint = SessionsEndpoint.class) @AutoConfigureAfter(SessionAutoConfiguration.class) public class SessionsEndpointAutoConfiguration { @Bean @ConditionalOnBean(FindByIndexNameSessionRepository.class) @ConditionalOnMissingBean - @ConditionalOnEnabledEndpoint public SessionsEndpoint sessionEndpoint( FindByIndexNameSessionRepository sessionRepository) { return new SessionsEndpoint(sessionRepository); diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/trace/http/HttpTraceEndpointAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/trace/http/HttpTraceEndpointAutoConfiguration.java index 10f28e7820..ec5b64eed6 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/trace/http/HttpTraceEndpointAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/trace/http/HttpTraceEndpointAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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. @@ -33,13 +33,13 @@ import org.springframework.context.annotation.Configuration; * @since 2.0.0 */ @Configuration +@ConditionalOnEnabledEndpoint(endpoint = HttpTraceEndpoint.class) @AutoConfigureAfter(HttpTraceAutoConfiguration.class) public class HttpTraceEndpointAutoConfiguration { @Bean @ConditionalOnBean(HttpTraceRepository.class) @ConditionalOnMissingBean - @ConditionalOnEnabledEndpoint public HttpTraceEndpoint httpTraceEndpoint(HttpTraceRepository traceRepository) { return new HttpTraceEndpoint(traceRepository); } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/condition/ConditionalOnEnabledEndpointTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/condition/ConditionalOnEnabledEndpointTests.java index 715fcdb43b..c77bfdda0c 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/condition/ConditionalOnEnabledEndpointTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/condition/ConditionalOnEnabledEndpointTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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. @@ -148,6 +148,14 @@ public class ConditionalOnEnabledEndpointTests { .run((context) -> assertThat(context).hasBean("fooBar")); } + @Test + public void outcomeWhenEndpointEnabledPropertyIsFalseOnClassShouldNotMatch() { + this.contextRunner.withPropertyValues("management.endpoint.foo.enabled=false") + .withUserConfiguration( + FooEndpointEnabledByDefaultTrueOnConfigurationConfiguration.class) + .run((context) -> assertThat(context).doesNotHaveBean("foo")); + } + @Endpoint(id = "foo", enableByDefault = true) static class FooEndpointEnabledByDefaultTrue { @@ -193,6 +201,17 @@ public class ConditionalOnEnabledEndpointTests { } + @Configuration + @ConditionalOnEnabledEndpoint(endpoint = FooEndpointEnabledByDefaultTrue.class) + static class FooEndpointEnabledByDefaultTrueOnConfigurationConfiguration { + + @Bean + public FooEndpointEnabledByDefaultTrue foo() { + return new FooEndpointEnabledByDefaultTrue(); + } + + } + @Configuration static class FooEndpointEnabledByDefaultFalseConfiguration {