Skip to content

Commit

Permalink
apollo-client-config-data support spring boot 3.0 (#5)
Browse files Browse the repository at this point in the history
* apollo-client-config-data support spring boot 3.0

* CHANGES.md

* AutoConfiguration
  • Loading branch information
vdiskg authored Dec 9, 2022
1 parent 3940553 commit 0a7b041
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 21 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Apollo Java 2.1.0
* [Add overloaded shortcut method to register BeanDefinition](https://github.com/apolloconfig/apollo/pull/4574)
* [Fix ApolloBootstrapPropertySources precedence issue](https://github.com/apolloconfig/apollo-java/pull/3)
* [Apollo Client Support Spring Boot 3.0](https://github.com/apolloconfig/apollo-java/pull/4)
* [apollo-client-config-data support spring boot 3.0](https://github.com/apolloconfig/apollo-java/pull/5)

------------------
All issues and pull requests are [here](https://github.com/apolloconfig/apollo-java/milestone/1?closed=1)
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.springframework.boot.ConfigurableBootstrapContext;
import org.springframework.boot.context.properties.bind.BindHandler;
import org.springframework.boot.context.properties.bind.Binder;
import org.springframework.boot.logging.DeferredLogFactory;

/**
* @author vdisk <vdisk@foxmail.com>
Expand All @@ -40,13 +41,15 @@ public class ApolloClientExtensionInitializeFactory {

private final ApolloClientWebsocketExtensionInitializer apolloClientWebsocketExtensionInitializer;

public ApolloClientExtensionInitializeFactory(Log log,
public ApolloClientExtensionInitializeFactory(DeferredLogFactory logFactory,
ConfigurableBootstrapContext bootstrapContext) {
this.log = log;
this.log = logFactory.getLog(ApolloClientExtensionInitializeFactory.class);
this.apolloClientPropertiesFactory = new ApolloClientPropertiesFactory();
this.apolloClientLongPollingExtensionInitializer = new ApolloClientLongPollingExtensionInitializer(log,
this.apolloClientLongPollingExtensionInitializer = new ApolloClientLongPollingExtensionInitializer(
logFactory,
bootstrapContext);
this.apolloClientWebsocketExtensionInitializer = new ApolloClientWebsocketExtensionInitializer(log,
this.apolloClientWebsocketExtensionInitializer = new ApolloClientWebsocketExtensionInitializer(
logFactory,
bootstrapContext);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.springframework.boot.ConfigurableBootstrapContext;
import org.springframework.boot.context.properties.bind.BindHandler;
import org.springframework.boot.context.properties.bind.Binder;
import org.springframework.boot.logging.DeferredLogFactory;
import org.springframework.boot.web.reactive.function.client.WebClientCustomizer;
import org.springframework.util.CollectionUtils;
import org.springframework.web.reactive.function.client.WebClient;
Expand All @@ -41,9 +42,9 @@ public class ApolloClientLongPollingExtensionInitializer implements

private final ConfigurableBootstrapContext bootstrapContext;

public ApolloClientLongPollingExtensionInitializer(Log log,
public ApolloClientLongPollingExtensionInitializer(DeferredLogFactory logFactory,
ConfigurableBootstrapContext bootstrapContext) {
this.log = log;
this.log = logFactory.getLog(ApolloClientLongPollingExtensionInitializer.class);
this.bootstrapContext = bootstrapContext;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.springframework.boot.ConfigurableBootstrapContext;
import org.springframework.boot.context.properties.bind.BindHandler;
import org.springframework.boot.context.properties.bind.Binder;
import org.springframework.boot.logging.DeferredLogFactory;

/**
* @author vdisk <vdisk@foxmail.com>
Expand All @@ -32,9 +33,9 @@ public class ApolloClientWebsocketExtensionInitializer implements ApolloClientEx

private final ConfigurableBootstrapContext bootstrapContext;

public ApolloClientWebsocketExtensionInitializer(Log log,
public ApolloClientWebsocketExtensionInitializer(DeferredLogFactory logFactory,
ConfigurableBootstrapContext bootstrapContext) {
this.log = log;
this.log = logFactory.getLog(ApolloClientWebsocketExtensionInitializer.class);
this.bootstrapContext = bootstrapContext;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.springframework.boot.context.config.ConfigDataResourceNotFoundException;
import org.springframework.boot.context.properties.bind.BindHandler;
import org.springframework.boot.context.properties.bind.Binder;
import org.springframework.boot.logging.DeferredLogFactory;
import org.springframework.core.Ordered;
import org.springframework.core.env.PropertySource;

Expand All @@ -42,10 +43,13 @@
*/
public class ApolloConfigDataLoader implements ConfigDataLoader<ApolloConfigDataResource>, Ordered {

private final DeferredLogFactory logFactory;

private final Log log;

public ApolloConfigDataLoader(Log log) {
this.log = log;
public ApolloConfigDataLoader(DeferredLogFactory logFactory) {
this.logFactory = logFactory;
this.log = logFactory.getLog(ApolloConfigDataLoader.class);
}

@Override
Expand All @@ -55,7 +59,7 @@ public ConfigData load(ConfigDataLoaderContext context, ApolloConfigDataResource
Binder binder = bootstrapContext.get(Binder.class);
BindHandler bindHandler = this.getBindHandler(context);
bootstrapContext.registerIfAbsent(ApolloConfigDataLoaderInitializer.class, InstanceSupplier
.from(() -> new ApolloConfigDataLoaderInitializer(this.log, binder, bindHandler,
.from(() -> new ApolloConfigDataLoaderInitializer(this.logFactory, binder, bindHandler,
bootstrapContext)));
ApolloConfigDataLoaderInitializer apolloConfigDataLoaderInitializer = bootstrapContext
.get(ApolloConfigDataLoaderInitializer.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.springframework.boot.context.properties.bind.Bindable;
import org.springframework.boot.context.properties.bind.Binder;
import org.springframework.boot.context.properties.source.ConfigurationPropertyName;
import org.springframework.boot.logging.DeferredLogFactory;
import org.springframework.core.env.MapPropertySource;
import org.springframework.core.env.PropertySource;

Expand All @@ -45,6 +46,8 @@ class ApolloConfigDataLoaderInitializer {

private static volatile boolean INITIALIZED = false;

private final DeferredLogFactory logFactory;

private final Log log;

private final Binder binder;
Expand All @@ -53,10 +56,11 @@ class ApolloConfigDataLoaderInitializer {

private final ConfigurableBootstrapContext bootstrapContext;

public ApolloConfigDataLoaderInitializer(Log log,
public ApolloConfigDataLoaderInitializer(DeferredLogFactory logFactory,
Binder binder, BindHandler bindHandler,
ConfigurableBootstrapContext bootstrapContext) {
this.log = log;
this.logFactory = logFactory;
this.log = logFactory.getLog(ApolloConfigDataLoaderInitializer.class);
this.binder = binder;
this.bindHandler = bindHandler;
this.bootstrapContext = bootstrapContext;
Expand Down Expand Up @@ -98,9 +102,9 @@ public List<PropertySource<?>> initApolloClient() {
}

private void initApolloClientInternal() {
new ApolloClientSystemPropertyInitializer(this.log)
new ApolloClientSystemPropertyInitializer(this.logFactory)
.initializeSystemProperty(this.binder, this.bindHandler);
new ApolloClientExtensionInitializeFactory(this.log,
new ApolloClientExtensionInitializeFactory(this.logFactory,
this.bootstrapContext).initializeExtension(this.binder, this.bindHandler);
DeferredLogger.enable();
ApolloConfigDataInjectorCustomizer.register(ConfigFactory.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.springframework.boot.context.config.ConfigDataLocationResolverContext;
import org.springframework.boot.context.config.ConfigDataResourceNotFoundException;
import org.springframework.boot.context.config.Profiles;
import org.springframework.boot.logging.DeferredLogFactory;
import org.springframework.core.Ordered;
import org.springframework.util.StringUtils;

Expand All @@ -40,8 +41,8 @@ public class ApolloConfigDataLocationResolver implements

private final Log log;

public ApolloConfigDataLocationResolver(Log log) {
this.log = log;
public ApolloConfigDataLocationResolver(DeferredLogFactory logFactory) {
this.log = logFactory.getLog(ApolloConfigDataLocationResolver.class);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.springframework.boot.context.properties.bind.BindHandler;
import org.springframework.boot.context.properties.bind.Bindable;
import org.springframework.boot.context.properties.bind.Binder;
import org.springframework.boot.logging.DeferredLogFactory;
import org.springframework.util.StringUtils;

/**
Expand All @@ -31,8 +32,8 @@ public class ApolloClientSystemPropertyInitializer {

private final Log log;

public ApolloClientSystemPropertyInitializer(Log log) {
this.log = log;
public ApolloClientSystemPropertyInitializer(DeferredLogFactory logFactory) {
this.log = logFactory.getLog(ApolloClientSystemPropertyInitializer.class);
}

public void initializeSystemProperty(Binder binder, BindHandler bindHandler) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
com.ctrip.framework.apollo.config.data.ApolloClientConfigDataAutoConfiguration
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.concurrent.ThreadLocalRandom;
import org.apache.commons.logging.LogFactory;
import java.util.function.Supplier;
import org.junit.After;
import org.junit.Assert;
import org.junit.Test;
Expand Down Expand Up @@ -50,7 +50,7 @@ public void testInitializeSystemProperty() {
MapConfigurationPropertySource propertySource = new MapConfigurationPropertySource(map);
Binder binder = new Binder(propertySource);
ApolloClientSystemPropertyInitializer initializer = new ApolloClientSystemPropertyInitializer(
LogFactory.getLog(ApolloClientSystemPropertyInitializerTest.class));
Supplier::get);
initializer.initializeSystemProperty(binder, null);
for (String propertyName : ApolloApplicationContextInitializer.APOLLO_SYSTEM_PROPERTIES) {
Assert.assertEquals(map.get(propertyName), System.getProperty(propertyName));
Expand Down

0 comments on commit 0a7b041

Please sign in to comment.