Skip import check if consul disabled.

This commit is contained in:
spencergibb
2021-03-10 14:21:20 -05:00
parent 99f01b4e8c
commit 10849c922c
2 changed files with 12 additions and 4 deletions

View File

@@ -21,6 +21,7 @@ import org.springframework.boot.context.config.ConfigDataEnvironmentPostProcesso
import org.springframework.boot.diagnostics.AbstractFailureAnalyzer;
import org.springframework.boot.diagnostics.FailureAnalysis;
import org.springframework.boot.env.EnvironmentPostProcessor;
import org.springframework.cloud.consul.ConsulProperties;
import org.springframework.core.Ordered;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.util.StringUtils;
@@ -48,14 +49,12 @@ public class ConsulConfigDataMissingEnvironmentPostProcessor implements Environm
if (bootstrapEnabled(environment) || useLegacyProcessing(environment)) {
return;
}
boolean coreEnabled = environment.getProperty(ConsulProperties.PREFIX + ".enabled", Boolean.class, true);
boolean configEnabled = environment.getProperty(ConsulConfigProperties.PREFIX + ".enabled", Boolean.class,
true);
if (!configEnabled) {
return;
}
boolean importCheckEnabled = environment.getProperty(ConsulConfigProperties.PREFIX + ".import-check.enabled",
Boolean.class, true);
if (!importCheckEnabled) {
if (!coreEnabled || !configEnabled || !importCheckEnabled) {
return;
}
String property = environment.getProperty("spring.config.import");

View File

@@ -79,6 +79,15 @@ public class ConsulConfigDataNoImportIntegrationTests {
.contains("Add a spring.config.import=consul: property to your configuration");
}
@Test
public void noExceptionThrownIfConsulDisabled() {
try (ConfigurableApplicationContext context = new SpringApplicationBuilder(Config.class)
.web(WebApplicationType.NONE)
.run("--spring.cloud.consul.enabled=false", "--spring.application.name=" + APP_NAME)) {
// nothing to do
}
}
@Test
public void noExceptionThrownIfConsulConfigDisabled() {
try (ConfigurableApplicationContext context = new SpringApplicationBuilder(Config.class)