Migrates from Bootstrap to BootstrapRegistryInitializer

This commit is contained in:
spencergibb
2021-07-15 14:31:58 -04:00
parent eb26025e97
commit 91e6e5d32a
5 changed files with 19 additions and 19 deletions

View File

@@ -25,10 +25,10 @@ import org.apache.curator.framework.CuratorFramework;
import org.springframework.boot.BootstrapContext;
import org.springframework.boot.BootstrapRegistry;
import org.springframework.boot.Bootstrapper;
import org.springframework.boot.BootstrapRegistryInitializer;
import org.springframework.cloud.zookeeper.CuratorFrameworkCustomizer;
public class ZookeeperBootstrapper implements Bootstrapper {
public class ZookeeperBootstrapper implements BootstrapRegistryInitializer {
private Function<BootstrapContext, RetryPolicy> retryPolicy;
@@ -38,7 +38,7 @@ public class ZookeeperBootstrapper implements Bootstrapper {
private Function<BootstrapContext, CuratorFrameworkCustomizer> curatorFrameworkCustomizer;
static Bootstrapper fromBootstrapContext(Function<BootstrapContext, CuratorFramework> factory) {
static BootstrapRegistryInitializer fromBootstrapContext(Function<BootstrapContext, CuratorFramework> factory) {
return registry -> registry.register(CuratorFramework.class, factory::apply);
}
@@ -67,7 +67,7 @@ public class ZookeeperBootstrapper implements Bootstrapper {
}
@Override
public void intitialize(BootstrapRegistry registry) {
public void initialize(BootstrapRegistry registry) {
register(registry, RetryPolicy.class, retryPolicy);
register(registry, EnsembleProvider.class, ensembleProvider);
register(registry, TracerDriver.class, tracerDriver);

View File

@@ -29,7 +29,7 @@ import org.junit.Test;
import org.springframework.boot.BootstrapContext;
import org.springframework.boot.BootstrapRegistry;
import org.springframework.boot.Bootstrapper;
import org.springframework.boot.BootstrapRegistryInitializer;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
@@ -67,8 +67,8 @@ public class ZookeeperConfigDataCustomizationIntegrationTests {
this.context = new SpringApplicationBuilder(Config.class)
.listeners(new ZookeeperTestingServer())
.web(WebApplicationType.NONE)
.addBootstrapper(bindHandlerBootstrapper)
.addBootstrapper(ZookeeperBootstrapper.fromBootstrapContext(this::curatorFramework))
.addBootstrapRegistryInitializer(bindHandlerBootstrapper)
.addBootstrapRegistryInitializer(ZookeeperBootstrapper.fromBootstrapContext(this::curatorFramework))
.run("--spring.config.import=zookeeper:",
"--spring.application.name=testZkConfigDataIntegration",
"--logging.level.org.springframework.cloud.zookeeper=DEBUG",
@@ -118,12 +118,12 @@ public class ZookeeperConfigDataCustomizationIntegrationTests {
}
static class BindHandlerBootstrapper implements Bootstrapper {
static class BindHandlerBootstrapper implements BootstrapRegistryInitializer {
private int onSuccessCount = 0;
@Override
public void intitialize(BootstrapRegistry registry) {
public void initialize(BootstrapRegistry registry) {
registry.register(BindHandler.class, context -> new BindHandler() {
@Override
public Object onSuccess(ConfigurationPropertyName name, Bindable<?> target, BindContext context,

View File

@@ -23,7 +23,7 @@ import org.apache.curator.x.discovery.details.InstanceSerializer;
import org.apache.curator.x.discovery.details.JsonInstanceSerializer;
import org.springframework.boot.BootstrapRegistry;
import org.springframework.boot.Bootstrapper;
import org.springframework.boot.BootstrapRegistryInitializer;
import org.springframework.boot.context.properties.bind.BindHandler;
import org.springframework.boot.context.properties.bind.Bindable;
import org.springframework.boot.context.properties.bind.Binder;
@@ -40,11 +40,11 @@ import org.springframework.cloud.zookeeper.support.DefaultServiceDiscoveryCustom
import org.springframework.cloud.zookeeper.support.ServiceDiscoveryCustomizer;
import org.springframework.util.ClassUtils;
public class ZookeeperConfigServerBootstrapper implements Bootstrapper {
public class ZookeeperConfigServerBootstrapper implements BootstrapRegistryInitializer {
@Override
@SuppressWarnings("unchecked")
public void intitialize(BootstrapRegistry registry) {
public void initialize(BootstrapRegistry registry) {
if (!ClassUtils.isPresent("org.springframework.cloud.config.client.ConfigServerInstanceProvider", null)) {
return;
}

View File

@@ -19,5 +19,5 @@ org.springframework.cloud.zookeeper.discovery.dependency.DependencyEnvironmentPo
org.springframework.cloud.bootstrap.BootstrapConfiguration=\
org.springframework.cloud.zookeeper.discovery.configclient.ZookeeperDiscoveryClientConfigServiceBootstrapConfiguration
org.springframework.boot.Bootstrapper=\
org.springframework.boot.BootstrapRegistryInitializer=\
org.springframework.cloud.zookeeper.discovery.configclient.ZookeeperConfigServerBootstrapper

View File

@@ -24,7 +24,7 @@ import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.boot.BootstrapRegistry;
import org.springframework.boot.Bootstrapper;
import org.springframework.boot.BootstrapRegistryInitializer;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
@@ -56,7 +56,7 @@ public class ZookeeperConfigServerBootstrapperTests {
ConfigurableApplicationContext context = new SpringApplicationBuilder(TestConfig.class)
.listeners(new ZookeeperTestingServer())
.properties("--server.port=0", "spring.cloud.service-registry.auto-registration.enabled=false")
.addBootstrapper(registry -> registry.addCloseListener(event -> {
.addBootstrapRegistryInitializer(registry -> registry.addCloseListener(event -> {
ConfigServerInstanceProvider.Function providerFn = event.getBootstrapContext()
.get(ConfigServerInstanceProvider.Function.class);
assertThat(providerFn).as("ConfigServerInstanceProvider.Function was created when it shouldn't")
@@ -78,8 +78,8 @@ public class ZookeeperConfigServerBootstrapperTests {
.properties("--server.port=0", "spring.cloud.config.discovery.enabled=true",
"spring.cloud.zookeeper.discovery.metadata[mymetadataprop]=mymetadataval",
"spring.cloud.service-registry.auto-registration.enabled=false")
.addBootstrapper(bindHandlerBootstrapper)
.addBootstrapper(registry -> registry.addCloseListener(event -> {
.addBootstrapRegistryInitializer(bindHandlerBootstrapper)
.addBootstrapRegistryInitializer(registry -> registry.addCloseListener(event -> {
ConfigServerInstanceProvider.Function providerFn = event.getBootstrapContext()
.get(ConfigServerInstanceProvider.Function.class);
assertThat(providerFn).as("ConfigServerInstanceProvider.Function was not created when it should.")
@@ -97,12 +97,12 @@ public class ZookeeperConfigServerBootstrapperTests {
static class TestConfig {
}
static class BindHandlerBootstrapper implements Bootstrapper {
static class BindHandlerBootstrapper implements BootstrapRegistryInitializer {
private int onSuccessCount = 0;
@Override
public void intitialize(BootstrapRegistry registry) {
public void initialize(BootstrapRegistry registry) {
registry.register(BindHandler.class, context -> new BindHandler() {
@Override
public Object onSuccess(ConfigurationPropertyName name, Bindable<?> target, BindContext context,