Merge branch '2.0.x'
# Conflicts: # spring-cloud-commons/src/main/java/org/springframework/cloud/client/CommonsClientAutoConfiguration.java # spring-cloud-commons/src/test/java/org/springframework/cloud/client/CommonsClientAutoConfigurationTests.java
This commit is contained in:
@@ -1,4 +1,8 @@
|
||||
// Do not edit this file (e.g. go instead to src/main/asciidoc)
|
||||
////
|
||||
DO NOT EDIT THIS FILE. IT WAS GENERATED.
|
||||
Manual changes to this file will be lost when it is generated again.
|
||||
Edit the files in the src/main/asciidoc/ directory instead.
|
||||
////
|
||||
|
||||
image::https://circleci.com/gh/spring-cloud/spring-cloud-commons.svg?style=svg[Build Status, link=https://circleci.com/gh/spring-cloud/spring-cloud-commons]
|
||||
|
||||
|
||||
@@ -46,6 +46,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
* {@link EnableAutoConfiguration Auto-configuration} for Spring Cloud Commons Client.
|
||||
*
|
||||
* @author Spencer Gibb
|
||||
* @author Olga Maciaszek-Sharma
|
||||
*/
|
||||
@Configuration
|
||||
@AutoConfigureOrder(0)
|
||||
@@ -55,7 +56,7 @@ public class CommonsClientAutoConfiguration {
|
||||
@EnableConfigurationProperties(DiscoveryClientHealthIndicatorProperties.class)
|
||||
@ConditionalOnClass(HealthIndicator.class)
|
||||
@ConditionalOnBean(DiscoveryClient.class)
|
||||
@ConditionalOnProperty(value = "spring.cloud.discovery.enabled", matchIfMissing = true)
|
||||
@ConditionalOnDiscoveryEnabled
|
||||
protected static class DiscoveryLoadBalancerConfiguration {
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright 2019-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.
|
||||
* 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.cloud.client;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Inherited;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
|
||||
/**
|
||||
* Provides a more succinct conditional <code>spring.cloud.discovery.enabled</code>.
|
||||
*
|
||||
* @since 2.0
|
||||
* @author Olga Maciaszek-Sharma
|
||||
*/
|
||||
@Target(ElementType.TYPE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@Inherited
|
||||
@ConditionalOnProperty(value = "spring.cloud.discovery.enabled", matchIfMissing = true)
|
||||
public @interface ConditionalOnDiscoveryEnabled {
|
||||
|
||||
}
|
||||
@@ -28,6 +28,7 @@ import org.springframework.cloud.client.discovery.health.DiscoveryClientHealthIn
|
||||
import org.springframework.cloud.client.discovery.health.DiscoveryCompositeHealthIndicator;
|
||||
import org.springframework.cloud.client.discovery.noop.NoopDiscoveryClientAutoConfiguration;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
@@ -36,6 +37,7 @@ import static org.assertj.core.api.BDDAssertions.then;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
* @author Olga Maciaszek-Sharma
|
||||
*/
|
||||
public class CommonsClientAutoConfigurationTests {
|
||||
|
||||
@@ -86,6 +88,18 @@ public class CommonsClientAutoConfigurationTests {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void conditionalOnDiscoveryEnabledWorks() {
|
||||
try (ConfigurableApplicationContext context = init(
|
||||
"spring.cloud.discovery.enabled=false")) {
|
||||
assertBeanNonExistant(context, TestBean.class);
|
||||
}
|
||||
try (ConfigurableApplicationContext context = init(
|
||||
"spring.cloud.discovery.enabled=true")) {
|
||||
assertThat(context.getBean(TestBean.class), is(notNullValue()));
|
||||
}
|
||||
}
|
||||
|
||||
private void assertBeanNonExistant(ConfigurableApplicationContext ctxt,
|
||||
Class<?> beanClass) {
|
||||
try {
|
||||
@@ -104,9 +118,23 @@ public class CommonsClientAutoConfigurationTests {
|
||||
|
||||
@Configuration
|
||||
@EnableAutoConfiguration
|
||||
@Import(NoopDiscoveryClientAutoConfiguration.class)
|
||||
@Import({NoopDiscoveryClientAutoConfiguration.class, DiscoveryEnabledConfig.class})
|
||||
protected static class Config {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Configuration
|
||||
@ConditionalOnDiscoveryEnabled
|
||||
protected static class DiscoveryEnabledConfig {
|
||||
@Bean
|
||||
TestBean testBean() {
|
||||
return new TestBean();
|
||||
}
|
||||
}
|
||||
|
||||
private static class TestBean {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user