Merge branch '2.1.x'

pull/15642/head
Stephane Nicoll 6 years ago
commit 5e736c0d1f

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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 @Configuration
@AutoConfigureAfter(AuditAutoConfiguration.class) @AutoConfigureAfter(AuditAutoConfiguration.class)
@ConditionalOnEnabledEndpoint(endpoint = AuditEventsEndpoint.class)
public class AuditEventsEndpointAutoConfiguration { public class AuditEventsEndpointAutoConfiguration {
@Bean @Bean
@ConditionalOnMissingBean @ConditionalOnMissingBean
@ConditionalOnBean(AuditEventRepository.class) @ConditionalOnBean(AuditEventRepository.class)
@ConditionalOnEnabledEndpoint
public AuditEventsEndpoint auditEventsEndpoint( public AuditEventsEndpoint auditEventsEndpoint(
AuditEventRepository auditEventRepository) { AuditEventRepository auditEventRepository) {
return new AuditEventsEndpoint(auditEventRepository); return new AuditEventsEndpoint(auditEventRepository);

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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 * @since 2.0.0
*/ */
@Configuration @Configuration
@ConditionalOnEnabledEndpoint(endpoint = BeansEndpoint.class)
public class BeansEndpointAutoConfiguration { public class BeansEndpointAutoConfiguration {
@Bean @Bean
@ConditionalOnMissingBean @ConditionalOnMissingBean
@ConditionalOnEnabledEndpoint
public BeansEndpoint beansEndpoint( public BeansEndpoint beansEndpoint(
ConfigurableApplicationContext applicationContext) { ConfigurableApplicationContext applicationContext) {
return new BeansEndpoint(applicationContext); return new BeansEndpoint(applicationContext);

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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 @Configuration
@ConditionalOnClass(CacheManager.class) @ConditionalOnClass(CacheManager.class)
@ConditionalOnEnabledEndpoint(endpoint = CachesEndpoint.class)
@AutoConfigureAfter(CacheAutoConfiguration.class) @AutoConfigureAfter(CacheAutoConfiguration.class)
public class CachesEndpointAutoConfiguration { public class CachesEndpointAutoConfiguration {
@Bean @Bean
@ConditionalOnMissingBean @ConditionalOnMissingBean
@ConditionalOnEnabledEndpoint
public CachesEndpoint cachesEndpoint( public CachesEndpoint cachesEndpoint(
ObjectProvider<Map<String, CacheManager>> cacheManagers) { ObjectProvider<Map<String, CacheManager>> cacheManagers) {
return new CachesEndpoint(cacheManagers.getIfAvailable(LinkedHashMap::new)); return new CachesEndpoint(cacheManagers.getIfAvailable(LinkedHashMap::new));
@ -55,7 +55,6 @@ public class CachesEndpointAutoConfiguration {
@Bean @Bean
@ConditionalOnMissingBean @ConditionalOnMissingBean
@ConditionalOnEnabledEndpoint
@ConditionalOnBean(CachesEndpoint.class) @ConditionalOnBean(CachesEndpoint.class)
public CachesEndpointWebExtension cachesEndpointWebExtension( public CachesEndpointWebExtension cachesEndpointWebExtension(
CachesEndpoint cachesEndpoint) { CachesEndpoint cachesEndpoint) {

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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 * @since 2.0.0
*/ */
@Configuration @Configuration
@ConditionalOnEnabledEndpoint(endpoint = ConditionsReportEndpoint.class)
public class ConditionsReportEndpointAutoConfiguration { public class ConditionsReportEndpointAutoConfiguration {
@Bean @Bean
@ConditionalOnMissingBean(search = SearchStrategy.CURRENT) @ConditionalOnMissingBean(search = SearchStrategy.CURRENT)
@ConditionalOnEnabledEndpoint
public ConditionsReportEndpoint conditionsReportEndpoint( public ConditionsReportEndpoint conditionsReportEndpoint(
ConfigurableApplicationContext context) { ConfigurableApplicationContext context) {
return new ConditionsReportEndpoint(context); return new ConditionsReportEndpoint(context);

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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 * @since 2.0.0
*/ */
@Configuration @Configuration
@ConditionalOnEnabledEndpoint(endpoint = ShutdownEndpoint.class)
public class ShutdownEndpointAutoConfiguration { public class ShutdownEndpointAutoConfiguration {
@Bean @Bean
@ConditionalOnMissingBean @ConditionalOnMissingBean
@ConditionalOnEnabledEndpoint
public ShutdownEndpoint shutdownEndpoint() { public ShutdownEndpoint shutdownEndpoint() {
return new ShutdownEndpoint(); return new ShutdownEndpoint();
} }

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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 * @since 2.0.0
*/ */
@Configuration @Configuration
@ConditionalOnEnabledEndpoint(endpoint = ConfigurationPropertiesReportEndpoint.class)
@EnableConfigurationProperties(ConfigurationPropertiesReportEndpointProperties.class) @EnableConfigurationProperties(ConfigurationPropertiesReportEndpointProperties.class)
public class ConfigurationPropertiesReportEndpointAutoConfiguration { public class ConfigurationPropertiesReportEndpointAutoConfiguration {
@ -45,7 +46,6 @@ public class ConfigurationPropertiesReportEndpointAutoConfiguration {
@Bean @Bean
@ConditionalOnMissingBean @ConditionalOnMissingBean
@ConditionalOnEnabledEndpoint
public ConfigurationPropertiesReportEndpoint configurationPropertiesReportEndpoint() { public ConfigurationPropertiesReportEndpoint configurationPropertiesReportEndpoint() {
ConfigurationPropertiesReportEndpoint endpoint = new ConfigurationPropertiesReportEndpoint(); ConfigurationPropertiesReportEndpoint endpoint = new ConfigurationPropertiesReportEndpoint();
String[] keysToSanitize = this.properties.getKeysToSanitize(); String[] keysToSanitize = this.properties.getKeysToSanitize();

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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 * @see Endpoint
*/ */
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD) @Target({ ElementType.METHOD, ElementType.TYPE })
@Documented @Documented
@Conditional(OnEnabledEndpointCondition.class) @Conditional(OnEnabledEndpointCondition.class)
public @interface ConditionalOnEnabledEndpoint { public @interface ConditionalOnEnabledEndpoint {

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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, private AnnotationAttributes getEndpointAttributes(ConditionContext context,
AnnotatedTypeMetadata metadata) { AnnotatedTypeMetadata metadata) {
Assert.state( return getEndpointAttributes(getEndpointType(context, metadata));
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);
} }
private Class<?> getEndpointType(ConditionContext context, MethodMetadata metadata) { private Class<?> getEndpointType(ConditionContext context,
AnnotatedTypeMetadata metadata) {
Map<String, Object> attributes = metadata Map<String, Object> attributes = metadata
.getAnnotationAttributes(ConditionalOnEnabledEndpoint.class.getName()); .getAnnotationAttributes(ConditionalOnEnabledEndpoint.class.getName());
if (attributes != null && attributes.containsKey("endpoint")) { if (attributes != null && attributes.containsKey("endpoint")) {
@ -107,15 +103,19 @@ class OnEnabledEndpointCondition extends SpringBootCondition {
return target; 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 { try {
return ClassUtils.forName(metadata.getReturnTypeName(), return ClassUtils.forName(methodMetadata.getReturnTypeName(),
context.getClassLoader()); context.getClassLoader());
} }
catch (Throwable ex) { catch (Throwable ex) {
throw new IllegalStateException("Failed to extract endpoint id for " throw new IllegalStateException("Failed to extract endpoint id for "
+ metadata.getDeclaringClassName() + "." + metadata.getMethodName(), + methodMetadata.getDeclaringClassName() + "."
ex); + methodMetadata.getMethodName(), ex);
} }
} }

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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 * @since 2.0.0
*/ */
@Configuration @Configuration
@ConditionalOnEnabledEndpoint(endpoint = EnvironmentEndpoint.class)
@EnableConfigurationProperties(EnvironmentEndpointProperties.class) @EnableConfigurationProperties(EnvironmentEndpointProperties.class)
public class EnvironmentEndpointAutoConfiguration { public class EnvironmentEndpointAutoConfiguration {
@ -47,7 +48,6 @@ public class EnvironmentEndpointAutoConfiguration {
@Bean @Bean
@ConditionalOnMissingBean @ConditionalOnMissingBean
@ConditionalOnEnabledEndpoint
public EnvironmentEndpoint environmentEndpoint(Environment environment) { public EnvironmentEndpoint environmentEndpoint(Environment environment) {
EnvironmentEndpoint endpoint = new EnvironmentEndpoint(environment); EnvironmentEndpoint endpoint = new EnvironmentEndpoint(environment);
String[] keysToSanitize = this.properties.getKeysToSanitize(); String[] keysToSanitize = this.properties.getKeysToSanitize();
@ -59,7 +59,6 @@ public class EnvironmentEndpointAutoConfiguration {
@Bean @Bean
@ConditionalOnMissingBean @ConditionalOnMissingBean
@ConditionalOnEnabledEndpoint
@ConditionalOnBean(EnvironmentEndpoint.class) @ConditionalOnBean(EnvironmentEndpoint.class)
public EnvironmentEndpointWebExtension environmentEndpointWebExtension( public EnvironmentEndpointWebExtension environmentEndpointWebExtension(
EnvironmentEndpoint environmentEndpoint) { EnvironmentEndpoint environmentEndpoint) {

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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 @Configuration
@ConditionalOnClass(Flyway.class) @ConditionalOnClass(Flyway.class)
@ConditionalOnEnabledEndpoint(endpoint = FlywayEndpoint.class)
@AutoConfigureAfter(FlywayAutoConfiguration.class) @AutoConfigureAfter(FlywayAutoConfiguration.class)
public class FlywayEndpointAutoConfiguration { public class FlywayEndpointAutoConfiguration {
@Bean @Bean
@ConditionalOnBean(Flyway.class) @ConditionalOnBean(Flyway.class)
@ConditionalOnMissingBean @ConditionalOnMissingBean
@ConditionalOnEnabledEndpoint
public FlywayEndpoint flywayEndpoint(ApplicationContext context) { public FlywayEndpoint flywayEndpoint(ApplicationContext context) {
return new FlywayEndpoint(context); return new FlywayEndpoint(context);
} }

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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 @Configuration
@ConditionalOnSingleCandidate(HealthIndicatorRegistry.class) @ConditionalOnSingleCandidate(HealthIndicatorRegistry.class)
@ConditionalOnEnabledEndpoint(endpoint = HealthEndpoint.class)
class HealthEndpointConfiguration { class HealthEndpointConfiguration {
@Bean @Bean
@ConditionalOnMissingBean @ConditionalOnMissingBean
@ConditionalOnEnabledEndpoint
public HealthEndpoint healthEndpoint(HealthAggregator healthAggregator, public HealthEndpoint healthEndpoint(HealthAggregator healthAggregator,
HealthIndicatorRegistry registry) { HealthIndicatorRegistry registry) {
return new HealthEndpoint( return new HealthEndpoint(

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -69,6 +69,7 @@ class HealthEndpointWebExtensionConfiguration {
@Configuration @Configuration
@ConditionalOnWebApplication(type = Type.REACTIVE) @ConditionalOnWebApplication(type = Type.REACTIVE)
@ConditionalOnSingleCandidate(ReactiveHealthIndicatorRegistry.class) @ConditionalOnSingleCandidate(ReactiveHealthIndicatorRegistry.class)
@ConditionalOnEnabledEndpoint(endpoint = HealthEndpoint.class)
static class ReactiveWebHealthConfiguration { static class ReactiveWebHealthConfiguration {
private final ReactiveHealthIndicator reactiveHealthIndicator; private final ReactiveHealthIndicator reactiveHealthIndicator;
@ -82,7 +83,6 @@ class HealthEndpointWebExtensionConfiguration {
@Bean @Bean
@ConditionalOnMissingBean @ConditionalOnMissingBean
@ConditionalOnEnabledEndpoint
@ConditionalOnBean(HealthEndpoint.class) @ConditionalOnBean(HealthEndpoint.class)
public ReactiveHealthEndpointWebExtension reactiveHealthEndpointWebExtension( public ReactiveHealthEndpointWebExtension reactiveHealthEndpointWebExtension(
HealthWebEndpointResponseMapper responseMapper) { HealthWebEndpointResponseMapper responseMapper) {
@ -94,11 +94,11 @@ class HealthEndpointWebExtensionConfiguration {
@Configuration @Configuration
@ConditionalOnWebApplication(type = Type.SERVLET) @ConditionalOnWebApplication(type = Type.SERVLET)
@ConditionalOnEnabledEndpoint(endpoint = HealthEndpoint.class)
static class ServletWebHealthConfiguration { static class ServletWebHealthConfiguration {
@Bean @Bean
@ConditionalOnMissingBean @ConditionalOnMissingBean
@ConditionalOnEnabledEndpoint
@ConditionalOnBean(HealthEndpoint.class) @ConditionalOnBean(HealthEndpoint.class)
public HealthEndpointWebExtension healthEndpointWebExtension( public HealthEndpointWebExtension healthEndpointWebExtension(
HealthEndpoint healthEndpoint, HealthEndpoint healthEndpoint,

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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 * @since 2.0.0
*/ */
@Configuration @Configuration
@ConditionalOnEnabledEndpoint(endpoint = InfoEndpoint.class)
@AutoConfigureAfter(InfoContributorAutoConfiguration.class) @AutoConfigureAfter(InfoContributorAutoConfiguration.class)
public class InfoEndpointAutoConfiguration { public class InfoEndpointAutoConfiguration {
@Bean @Bean
@ConditionalOnMissingBean @ConditionalOnMissingBean
@ConditionalOnEnabledEndpoint
public InfoEndpoint infoEndpoint(ObjectProvider<InfoContributor> infoContributors) { public InfoEndpoint infoEndpoint(ObjectProvider<InfoContributor> infoContributors) {
return new InfoEndpoint( return new InfoEndpoint(
infoContributors.orderedStream().collect(Collectors.toList())); infoContributors.orderedStream().collect(Collectors.toList()));

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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 @Configuration
@ConditionalOnClass(IntegrationGraphServer.class) @ConditionalOnClass(IntegrationGraphServer.class)
@ConditionalOnBean(IntegrationConfigurationBeanFactoryPostProcessor.class) @ConditionalOnBean(IntegrationConfigurationBeanFactoryPostProcessor.class)
@ConditionalOnEnabledEndpoint(endpoint = IntegrationGraphEndpoint.class)
@AutoConfigureAfter(IntegrationAutoConfiguration.class) @AutoConfigureAfter(IntegrationAutoConfiguration.class)
public class IntegrationGraphEndpointAutoConfiguration { public class IntegrationGraphEndpointAutoConfiguration {
@Bean @Bean
@ConditionalOnMissingBean @ConditionalOnMissingBean
@ConditionalOnEnabledEndpoint
public IntegrationGraphEndpoint integrationGraphEndpoint( public IntegrationGraphEndpoint integrationGraphEndpoint(
IntegrationGraphServer integrationGraphServer) { IntegrationGraphServer integrationGraphServer) {
return new IntegrationGraphEndpoint(integrationGraphServer); return new IntegrationGraphEndpoint(integrationGraphServer);
@ -53,7 +53,6 @@ public class IntegrationGraphEndpointAutoConfiguration {
@Bean @Bean
@ConditionalOnMissingBean @ConditionalOnMissingBean
@ConditionalOnEnabledEndpoint(endpoint = IntegrationGraphEndpoint.class)
public IntegrationGraphServer integrationGraphServer() { public IntegrationGraphServer integrationGraphServer() {
return new IntegrationGraphServer(); return new IntegrationGraphServer();
} }

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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 @Configuration
@ConditionalOnWebApplication(type = Type.SERVLET) @ConditionalOnWebApplication(type = Type.SERVLET)
@ConditionalOnClass(AgentServlet.class) @ConditionalOnClass(AgentServlet.class)
@ConditionalOnEnabledEndpoint(endpoint = JolokiaEndpoint.class)
@EnableConfigurationProperties(JolokiaProperties.class) @EnableConfigurationProperties(JolokiaProperties.class)
public class JolokiaEndpointAutoConfiguration { public class JolokiaEndpointAutoConfiguration {
@Bean @Bean
@ConditionalOnEnabledEndpoint
public JolokiaEndpoint jolokiaEndpoint(JolokiaProperties properties) { public JolokiaEndpoint jolokiaEndpoint(JolokiaProperties properties) {
return new JolokiaEndpoint(properties.getConfig()); return new JolokiaEndpoint(properties.getConfig());
} }

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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 @Configuration
@ConditionalOnClass(SpringLiquibase.class) @ConditionalOnClass(SpringLiquibase.class)
@ConditionalOnEnabledEndpoint(endpoint = LiquibaseEndpoint.class)
@AutoConfigureAfter(LiquibaseAutoConfiguration.class) @AutoConfigureAfter(LiquibaseAutoConfiguration.class)
public class LiquibaseEndpointAutoConfiguration { public class LiquibaseEndpointAutoConfiguration {
@Bean @Bean
@ConditionalOnBean(SpringLiquibase.class) @ConditionalOnBean(SpringLiquibase.class)
@ConditionalOnMissingBean @ConditionalOnMissingBean
@ConditionalOnEnabledEndpoint
public LiquibaseEndpoint liquibaseEndpoint(ApplicationContext context) { public LiquibaseEndpoint liquibaseEndpoint(ApplicationContext context) {
return new LiquibaseEndpoint(context); return new LiquibaseEndpoint(context);
} }
@Bean @Bean
@ConditionalOnBean(SpringLiquibase.class) @ConditionalOnBean(SpringLiquibase.class)
@ConditionalOnEnabledEndpoint(endpoint = LiquibaseEndpoint.class)
public static BeanPostProcessor preventDataSourceCloseBeanPostProcessor() { public static BeanPostProcessor preventDataSourceCloseBeanPostProcessor() {
return new BeanPostProcessor() { return new BeanPostProcessor() {

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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 * @since 2.0.0
*/ */
@Configuration @Configuration
@ConditionalOnEnabledEndpoint(endpoint = LoggersEndpoint.class)
public class LoggersEndpointAutoConfiguration { public class LoggersEndpointAutoConfiguration {
@Bean @Bean
@ConditionalOnBean(LoggingSystem.class) @ConditionalOnBean(LoggingSystem.class)
@Conditional(OnEnabledLoggingSystemCondition.class) @Conditional(OnEnabledLoggingSystemCondition.class)
@ConditionalOnMissingBean @ConditionalOnMissingBean
@ConditionalOnEnabledEndpoint
public LoggersEndpoint loggersEndpoint(LoggingSystem loggingSystem) { public LoggersEndpoint loggersEndpoint(LoggingSystem loggingSystem) {
return new LoggersEndpoint(loggingSystem); return new LoggersEndpoint(loggingSystem);
} }

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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 * @since 2.0.0
*/ */
@Configuration @Configuration
@ConditionalOnEnabledEndpoint(endpoint = HeapDumpWebEndpoint.class)
public class HeapDumpWebEndpointAutoConfiguration { public class HeapDumpWebEndpointAutoConfiguration {
@Bean @Bean
@ConditionalOnMissingBean @ConditionalOnMissingBean
@ConditionalOnEnabledEndpoint
public HeapDumpWebEndpoint heapDumpWebEndpoint() { public HeapDumpWebEndpoint heapDumpWebEndpoint() {
return new HeapDumpWebEndpoint(); return new HeapDumpWebEndpoint();
} }

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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 * @since 2.0.0
*/ */
@Configuration @Configuration
@ConditionalOnEnabledEndpoint(endpoint = ThreadDumpEndpoint.class)
public class ThreadDumpEndpointAutoConfiguration { public class ThreadDumpEndpointAutoConfiguration {
@Bean @Bean
@ConditionalOnMissingBean @ConditionalOnMissingBean
@ConditionalOnEnabledEndpoint
public ThreadDumpEndpoint dumpEndpoint() { public ThreadDumpEndpoint dumpEndpoint() {
return new ThreadDumpEndpoint(); return new ThreadDumpEndpoint();
} }

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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 @Configuration
@ConditionalOnClass(Timed.class) @ConditionalOnClass(Timed.class)
@ConditionalOnEnabledEndpoint(endpoint = MetricsEndpoint.class)
@AutoConfigureAfter({ MetricsAutoConfiguration.class, @AutoConfigureAfter({ MetricsAutoConfiguration.class,
CompositeMeterRegistryAutoConfiguration.class }) CompositeMeterRegistryAutoConfiguration.class })
public class MetricsEndpointAutoConfiguration { public class MetricsEndpointAutoConfiguration {
@ -44,7 +45,6 @@ public class MetricsEndpointAutoConfiguration {
@Bean @Bean
@ConditionalOnBean(MeterRegistry.class) @ConditionalOnBean(MeterRegistry.class)
@ConditionalOnMissingBean @ConditionalOnMissingBean
@ConditionalOnEnabledEndpoint
public MetricsEndpoint metricsEndpoint(MeterRegistry registry) { public MetricsEndpoint metricsEndpoint(MeterRegistry registry) {
return new MetricsEndpoint(registry); return new MetricsEndpoint(registry);
} }

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -82,10 +82,10 @@ public class PrometheusMetricsExportAutoConfiguration {
} }
@Configuration @Configuration
@ConditionalOnEnabledEndpoint(endpoint = PrometheusScrapeEndpoint.class)
public static class PrometheusScrapeEndpointConfiguration { public static class PrometheusScrapeEndpointConfiguration {
@Bean @Bean
@ConditionalOnEnabledEndpoint
@ConditionalOnMissingBean @ConditionalOnMissingBean
public PrometheusScrapeEndpoint prometheusEndpoint( public PrometheusScrapeEndpoint prometheusEndpoint(
CollectorRegistry collectorRegistry) { CollectorRegistry collectorRegistry) {

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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 * @since 2.0.0
*/ */
@Configuration @Configuration
@ConditionalOnEnabledEndpoint(endpoint = ScheduledTasksEndpoint.class)
public class ScheduledTasksEndpointAutoConfiguration { public class ScheduledTasksEndpointAutoConfiguration {
@Bean @Bean
@ConditionalOnMissingBean @ConditionalOnMissingBean
@ConditionalOnEnabledEndpoint
public ScheduledTasksEndpoint scheduledTasksEndpoint( public ScheduledTasksEndpoint scheduledTasksEndpoint(
ObjectProvider<ScheduledTaskHolder> holders) { ObjectProvider<ScheduledTaskHolder> holders) {
return new ScheduledTasksEndpoint( return new ScheduledTasksEndpoint(

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -37,13 +37,13 @@ import org.springframework.session.Session;
*/ */
@Configuration @Configuration
@ConditionalOnClass(FindByIndexNameSessionRepository.class) @ConditionalOnClass(FindByIndexNameSessionRepository.class)
@ConditionalOnEnabledEndpoint(endpoint = SessionsEndpoint.class)
@AutoConfigureAfter(SessionAutoConfiguration.class) @AutoConfigureAfter(SessionAutoConfiguration.class)
public class SessionsEndpointAutoConfiguration { public class SessionsEndpointAutoConfiguration {
@Bean @Bean
@ConditionalOnBean(FindByIndexNameSessionRepository.class) @ConditionalOnBean(FindByIndexNameSessionRepository.class)
@ConditionalOnMissingBean @ConditionalOnMissingBean
@ConditionalOnEnabledEndpoint
public SessionsEndpoint sessionEndpoint( public SessionsEndpoint sessionEndpoint(
FindByIndexNameSessionRepository<? extends Session> sessionRepository) { FindByIndexNameSessionRepository<? extends Session> sessionRepository) {
return new SessionsEndpoint(sessionRepository); return new SessionsEndpoint(sessionRepository);

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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 * @since 2.0.0
*/ */
@Configuration @Configuration
@ConditionalOnEnabledEndpoint(endpoint = HttpTraceEndpoint.class)
@AutoConfigureAfter(HttpTraceAutoConfiguration.class) @AutoConfigureAfter(HttpTraceAutoConfiguration.class)
public class HttpTraceEndpointAutoConfiguration { public class HttpTraceEndpointAutoConfiguration {
@Bean @Bean
@ConditionalOnBean(HttpTraceRepository.class) @ConditionalOnBean(HttpTraceRepository.class)
@ConditionalOnMissingBean @ConditionalOnMissingBean
@ConditionalOnEnabledEndpoint
public HttpTraceEndpoint httpTraceEndpoint(HttpTraceRepository traceRepository) { public HttpTraceEndpoint httpTraceEndpoint(HttpTraceRepository traceRepository) {
return new HttpTraceEndpoint(traceRepository); return new HttpTraceEndpoint(traceRepository);
} }

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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")); .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) @Endpoint(id = "foo", enableByDefault = true)
static class FooEndpointEnabledByDefaultTrue { 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 @Configuration
static class FooEndpointEnabledByDefaultFalseConfiguration { static class FooEndpointEnabledByDefaultFalseConfiguration {

Loading…
Cancel
Save