Commit 0e4eb9ef by Dave Syer

Use @ConditionalOnProperty where possible

parent 90d7e5df
...@@ -19,8 +19,8 @@ import javax.annotation.PostConstruct; ...@@ -19,8 +19,8 @@ import javax.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; 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.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
...@@ -38,7 +38,7 @@ import com.netflix.discovery.converters.XmlXStream; ...@@ -38,7 +38,7 @@ import com.netflix.discovery.converters.XmlXStream;
@Configuration @Configuration
@EnableConfigurationProperties @EnableConfigurationProperties
@ConditionalOnClass(EurekaClientConfig.class) @ConditionalOnClass(EurekaClientConfig.class)
@ConditionalOnExpression("${eureka.client.enabled:true}") @ConditionalOnProperty(value = "eureka.client.enabled", matchIfMissing = true)
public class EurekaClientAutoConfiguration { public class EurekaClientAutoConfiguration {
@Autowired @Autowired
......
...@@ -28,8 +28,8 @@ import org.springframework.boot.actuate.endpoint.Endpoint; ...@@ -28,8 +28,8 @@ import org.springframework.boot.actuate.endpoint.Endpoint;
import org.springframework.boot.actuate.metrics.reader.MetricReader; import org.springframework.boot.actuate.metrics.reader.MetricReader;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; 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.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.embedded.EmbeddedServletContainerInitializedEvent; import org.springframework.boot.context.embedded.EmbeddedServletContainerInitializedEvent;
import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.client.discovery.DiscoveryClient; import org.springframework.cloud.client.discovery.DiscoveryClient;
...@@ -60,7 +60,7 @@ import com.netflix.discovery.shared.EurekaJerseyClient; ...@@ -60,7 +60,7 @@ import com.netflix.discovery.shared.EurekaJerseyClient;
@Configuration @Configuration
@EnableConfigurationProperties @EnableConfigurationProperties
@ConditionalOnClass(EurekaClientConfig.class) @ConditionalOnClass(EurekaClientConfig.class)
@ConditionalOnExpression("${eureka.client.enabled:true}") @ConditionalOnProperty(value = "eureka.client.enabled", matchIfMissing = true)
public class EurekaDiscoveryClientConfiguration implements SmartLifecycle, Ordered { public class EurekaDiscoveryClientConfiguration implements SmartLifecycle, Ordered {
private static final Logger logger = LoggerFactory private static final Logger logger = LoggerFactory
......
...@@ -20,7 +20,7 @@ import org.springframework.boot.actuate.autoconfigure.HealthIndicatorAutoConfigu ...@@ -20,7 +20,7 @@ import org.springframework.boot.actuate.autoconfigure.HealthIndicatorAutoConfigu
import org.springframework.boot.actuate.health.HealthIndicator; import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
...@@ -32,7 +32,7 @@ import com.netflix.hystrix.Hystrix; ...@@ -32,7 +32,7 @@ import com.netflix.hystrix.Hystrix;
*/ */
@Configuration @Configuration
@ConditionalOnClass({ Hystrix.class, HealthIndicator.class }) @ConditionalOnClass({ Hystrix.class, HealthIndicator.class })
@ConditionalOnExpression("${health.hystrix.enabled:true}") @ConditionalOnProperty(value = "health.hystrix.enabled", matchIfMissing = true)
@AutoConfigureAfter({ HealthIndicatorAutoConfiguration.class }) @AutoConfigureAfter({ HealthIndicatorAutoConfiguration.class })
public class HystrixAutoConfiguration { public class HystrixAutoConfiguration {
......
...@@ -16,12 +16,12 @@ ...@@ -16,12 +16,12 @@
package org.springframework.cloud.netflix.hystrix; package org.springframework.cloud.netflix.hystrix;
import com.fasterxml.jackson.databind.ObjectMapper; import java.io.IOException;
import com.netflix.hystrix.Hystrix; import java.util.Arrays;
import com.netflix.hystrix.contrib.javanica.aop.aspectj.HystrixCommandAspect; import java.util.HashSet;
import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsPoller; import java.util.Map;
import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsPoller.MetricsAsJsonPollerListener; import java.util.Set;
import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet;
import org.apache.catalina.core.ApplicationContext; import org.apache.catalina.core.ApplicationContext;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
...@@ -30,18 +30,19 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -30,18 +30,19 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.endpoint.Endpoint; import org.springframework.boot.actuate.endpoint.Endpoint;
import org.springframework.boot.actuate.metrics.GaugeService; import org.springframework.boot.actuate.metrics.GaugeService;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.context.SmartLifecycle; import org.springframework.context.SmartLifecycle;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered; import org.springframework.core.Ordered;
import java.io.IOException; import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.Arrays; import com.netflix.hystrix.Hystrix;
import java.util.HashSet; import com.netflix.hystrix.contrib.javanica.aop.aspectj.HystrixCommandAspect;
import java.util.Map; import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsPoller;
import java.util.Set; import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsPoller.MetricsAsJsonPollerListener;
import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet;
/** /**
* @author Spencer Gibb * @author Spencer Gibb
...@@ -61,7 +62,7 @@ public class HystrixCircuitBreakerConfiguration { ...@@ -61,7 +62,7 @@ public class HystrixCircuitBreakerConfiguration {
} }
@Configuration @Configuration
@ConditionalOnExpression("${hystrix.stream.endpoint.enabled:true}") @ConditionalOnProperty(value = "hystrix.stream.endpoint.enabled", matchIfMissing = true)
@ConditionalOnWebApplication @ConditionalOnWebApplication
@ConditionalOnClass({Endpoint.class, HystrixMetricsStreamServlet.class}) @ConditionalOnClass({Endpoint.class, HystrixMetricsStreamServlet.class})
protected static class HystrixWebConfiguration { protected static class HystrixWebConfiguration {
......
...@@ -18,7 +18,7 @@ package org.springframework.cloud.netflix.ribbon.eureka; ...@@ -18,7 +18,7 @@ package org.springframework.cloud.netflix.ribbon.eureka;
import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.netflix.ribbon.RibbonAutoConfiguration; import org.springframework.cloud.netflix.ribbon.RibbonAutoConfiguration;
import org.springframework.cloud.netflix.ribbon.RibbonClients; import org.springframework.cloud.netflix.ribbon.RibbonClients;
...@@ -35,7 +35,7 @@ import com.netflix.niws.loadbalancer.DiscoveryEnabledNIWSServerList; ...@@ -35,7 +35,7 @@ import com.netflix.niws.loadbalancer.DiscoveryEnabledNIWSServerList;
@EnableConfigurationProperties @EnableConfigurationProperties
@ConditionalOnClass(DiscoveryEnabledNIWSServerList.class) @ConditionalOnClass(DiscoveryEnabledNIWSServerList.class)
@ConditionalOnBean(SpringClientFactory.class) @ConditionalOnBean(SpringClientFactory.class)
@ConditionalOnExpression("${ribbon.eureka.enabled:true}") @ConditionalOnProperty(value = "ribbon.eureka.enabled", matchIfMissing = true)
@AutoConfigureAfter(RibbonAutoConfiguration.class) @AutoConfigureAfter(RibbonAutoConfiguration.class)
@RibbonClients(defaultConfiguration = EurekaRibbonClientConfiguration.class) @RibbonClients(defaultConfiguration = EurekaRibbonClientConfiguration.class)
public class RibbonEurekaAutoConfiguration { public class RibbonEurekaAutoConfiguration {
......
...@@ -7,7 +7,7 @@ import org.springframework.amqp.rabbit.core.RabbitTemplate; ...@@ -7,7 +7,7 @@ import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter; import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.netflix.Constants; import org.springframework.cloud.netflix.Constants;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
...@@ -27,7 +27,7 @@ import com.netflix.hystrix.HystrixCircuitBreaker; ...@@ -27,7 +27,7 @@ import com.netflix.hystrix.HystrixCircuitBreaker;
*/ */
@Configuration @Configuration
@ConditionalOnClass({ HystrixCircuitBreaker.class, RabbitTemplate.class }) @ConditionalOnClass({ HystrixCircuitBreaker.class, RabbitTemplate.class })
@ConditionalOnExpression("${hystrix.stream.amqp.enabled:true}") @ConditionalOnProperty(value = "hystrix.stream.amqp.enabled", matchIfMissing = true)
@IntegrationComponentScan(basePackageClasses = HystrixStreamChannel.class) @IntegrationComponentScan(basePackageClasses = HystrixStreamChannel.class)
@EnableConfigurationProperties @EnableConfigurationProperties
@EnableScheduling @EnableScheduling
......
package org.springframework.cloud.netflix.sidecar; package org.springframework.cloud.netflix.sidecar;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean; import org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
...@@ -12,7 +12,7 @@ import org.springframework.context.annotation.Configuration; ...@@ -12,7 +12,7 @@ import org.springframework.context.annotation.Configuration;
*/ */
@Configuration @Configuration
@EnableConfigurationProperties @EnableConfigurationProperties
@ConditionalOnExpression("${sidecar.enabled:true}") @ConditionalOnProperty(value = "sidecar.enabled", matchIfMissing = true)
public class SidecarConfiguration { public class SidecarConfiguration {
@Value("${server.port:${SERVER_PORT:${PORT:8080}}}") @Value("${server.port:${SERVER_PORT:${PORT:8080}}}")
private int serverPort = 8080; private int serverPort = 8080;
......
...@@ -15,7 +15,7 @@ import org.springframework.amqp.rabbit.core.RabbitTemplate; ...@@ -15,7 +15,7 @@ import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter; import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.cloud.netflix.Constants; import org.springframework.cloud.netflix.Constants;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
...@@ -30,7 +30,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; ...@@ -30,7 +30,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
*/ */
@Configuration @Configuration
@ConditionalOnClass(AmqpTemplate.class) @ConditionalOnClass(AmqpTemplate.class)
@ConditionalOnExpression("${turbine.amqp.enabled:true}") @ConditionalOnProperty(value = "turbine.amqp.enabled", matchIfMissing = true)
public class TurbineAmqpAutoConfiguration { public class TurbineAmqpAutoConfiguration {
@Autowired @Autowired
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment