Microservice without dependencies fix (#75)

* make the default value of spring.cloud.zookeeper.dependency.enabled consistently true

fixes #74
This commit is contained in:
Matúš Hennel
2016-04-18 20:33:07 +02:00
committed by Marcin Grzejszczak
parent 8ba93d4f1d
commit 02b800a7a8
5 changed files with 15 additions and 16 deletions

View File

@@ -25,7 +25,8 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Conditional;
/**
* Annotation to turn on a feature if Zookeeper dependencies have been passed
* Annotation to turn on a feature if Zookeeper dependencies have been passed.
* Also checks if switch for zookeeper dependencies is turned on.
*
* @author Marcin Grzejszczak
* @since 1.0.0

View File

@@ -20,8 +20,7 @@ import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;
/**
* Inverse of the {@link ConditionalOnDependenciesPassed} condition. Also checks if switch for zookeeper dependencies
* was turned on
* Inverse of the {@link ConditionalOnDependenciesPassed} condition.
*
* @author Marcin Grzejszczak
* @since 1.0.0
@@ -31,15 +30,7 @@ public class DependenciesNotPassedCondition extends DependenciesPassedCondition
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
ConditionOutcome propertiesSet = super.getMatchOutcome(context, metadata);
if (propertiesSet.isMatch()) {
return ConditionOutcome.inverse(propertiesSet);
}
Boolean dependenciesEnabled = context.getEnvironment()
.getProperty("spring.cloud.zookeeper.dependency.enabled", Boolean.class, false);
if (dependenciesEnabled) {
return ConditionOutcome.noMatch("Dependencies are defined in configuration and switch is turned on");
}
return ConditionOutcome.match("Dependencies are not defined in configuration and switch is turned off");
return ConditionOutcome.inverse(propertiesSet);
}
}

View File

@@ -37,9 +37,15 @@ public class DependenciesPassedCondition extends SpringBootCondition {
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
Map<String, Object> subProperties = new RelaxedPropertyResolver(context.getEnvironment()).getSubProperties(ZOOKEEPER_DEPENDENCIES_PROP);
return subProperties.isEmpty() ?
ConditionOutcome.noMatch("No dependencies have been passed for the service") :
ConditionOutcome.match();
if (!subProperties.isEmpty()) {
return ConditionOutcome.match("Dependencies are defined in configuration");
}
Boolean dependenciesEnabled = context.getEnvironment()
.getProperty("spring.cloud.zookeeper.dependency.enabled", Boolean.class, true);
if (dependenciesEnabled) {
return ConditionOutcome.match("Dependencies are not defined in configuration, but switch is turned on");
}
return ConditionOutcome.noMatch("No dependencies have been passed for the service");
}
}

View File

@@ -42,7 +42,7 @@ import static org.junit.Assert.assertTrue;
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = ZookeeperLifecycleRegistrationDisabledTests.TestPropsConfig.class)
@WebIntegrationTest(value = { "spring.application.name=myTestNotRegisteredService",
"spring.cloud.zookeeper.discovery.register=false"}, randomPort = true)
"spring.cloud.zookeeper.discovery.register=false", "spring.cloud.zookeeper.dependency.enabled=false"}, randomPort = true)
public class ZookeeperLifecycleRegistrationDisabledTests {
static TestingServer testingServer;

View File

@@ -1 +1,2 @@
spring.cloud.zookeeper.dependency.enabled: false
spring.application.name: me