From 7042018d42337d259563a783448ac28f1641f8cb Mon Sep 17 00:00:00 2001 From: spencergibb Date: Thu, 17 Sep 2020 18:11:04 -0400 Subject: [PATCH] Updates ConsulBootstrapper with more general helper. --- .../cloud/consul/config/ConsulBootstrapper.java | 7 ++++++- .../ConsulConfigDataCustomizationIntegrationTests.java | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/spring-cloud-consul-config/src/main/java/org/springframework/cloud/consul/config/ConsulBootstrapper.java b/spring-cloud-consul-config/src/main/java/org/springframework/cloud/consul/config/ConsulBootstrapper.java index 34fcb0c2..58ea5a06 100644 --- a/spring-cloud-consul-config/src/main/java/org/springframework/cloud/consul/config/ConsulBootstrapper.java +++ b/spring-cloud-consul-config/src/main/java/org/springframework/cloud/consul/config/ConsulBootstrapper.java @@ -20,16 +20,21 @@ import java.util.function.Function; import com.ecwid.consul.v1.ConsulClient; +import org.springframework.boot.BootstrapContext; import org.springframework.boot.Bootstrapper; import org.springframework.cloud.consul.ConsulProperties; public abstract class ConsulBootstrapper { - static Bootstrapper withConsulClient(Function factory) { + static Bootstrapper fromConsulProperties(Function factory) { return registry -> registry.register(ConsulClient.class, context -> { ConsulProperties properties = context.get(ConsulProperties.class); return factory.apply(properties); }); } + static Bootstrapper fromBootstrapContext(Function factory) { + return registry -> registry.register(ConsulClient.class, factory::apply); + } + } diff --git a/spring-cloud-consul-config/src/test/java/org/springframework/cloud/consul/config/ConsulConfigDataCustomizationIntegrationTests.java b/spring-cloud-consul-config/src/test/java/org/springframework/cloud/consul/config/ConsulConfigDataCustomizationIntegrationTests.java index 2598f261..324f3e3e 100644 --- a/spring-cloud-consul-config/src/test/java/org/springframework/cloud/consul/config/ConsulConfigDataCustomizationIntegrationTests.java +++ b/spring-cloud-consul-config/src/test/java/org/springframework/cloud/consul/config/ConsulConfigDataCustomizationIntegrationTests.java @@ -54,7 +54,7 @@ public class ConsulConfigDataCustomizationIntegrationTests { SpringApplication application = new SpringApplication(Config.class); application.setWebApplicationType(WebApplicationType.NONE); - application.addBootstrapper(ConsulBootstrapper.withConsulClient(TestConsulClient::new)); + application.addBootstrapper(ConsulBootstrapper.fromConsulProperties(TestConsulClient::new)); context = application.run("--spring.application.name=" + APP_NAME, "--spring.config.import=consul:" + ConsulTestcontainers.getHost() + ":" + ConsulTestcontainers.getPort(),