Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Apollo Java 2.5.0
* [Feature Provide a new open APl to return the organization list](https://github.com/apolloconfig/apollo-java/pull/102)
* [Feature Added a new feature to get instance count by namespace.](https://github.com/apolloconfig/apollo-java/pull/103)
* [Feature Support retry in open api client.](https://github.com/apolloconfig/apollo-java/pull/105)
* [Support Spring Boot 4.0 bootstrap context package relocation for apollo-client-config-data](https://github.com/apolloconfig/apollo-java/pull/115)

------------------
All issues and pull requests are [here](https://github.com/apolloconfig/apollo-java/milestone/5?closed=1)
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import com.ctrip.framework.apollo.config.data.extension.websocket.ApolloClientWebsocketExtensionInitializer;
import com.ctrip.framework.apollo.config.data.util.Slf4jLogMessageFormatter;
import org.apache.commons.logging.Log;
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;
Expand All @@ -42,7 +41,7 @@ public class ApolloClientExtensionInitializeFactory {
private final ApolloClientWebsocketExtensionInitializer apolloClientWebsocketExtensionInitializer;

public ApolloClientExtensionInitializeFactory(DeferredLogFactory logFactory,
ConfigurableBootstrapContext bootstrapContext) {
Object bootstrapContext) {
this.log = logFactory.getLog(ApolloClientExtensionInitializeFactory.class);
this.apolloClientPropertiesFactory = new ApolloClientPropertiesFactory();
this.apolloClientLongPollingExtensionInitializer = new ApolloClientLongPollingExtensionInitializer(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import com.ctrip.framework.foundation.internals.ServiceBootstrap;
import java.util.List;
import org.apache.commons.logging.Log;
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;
Expand All @@ -40,10 +39,10 @@ public class ApolloClientLongPollingExtensionInitializer implements

private final Log log;

private final ConfigurableBootstrapContext bootstrapContext;
private final Object bootstrapContext;

public ApolloClientLongPollingExtensionInitializer(DeferredLogFactory logFactory,
ConfigurableBootstrapContext bootstrapContext) {
Object bootstrapContext) {
this.log = logFactory.getLog(ApolloClientLongPollingExtensionInitializer.class);
this.bootstrapContext = bootstrapContext;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import com.ctrip.framework.apollo.config.data.extension.properties.ApolloClientProperties;
import com.ctrip.framework.apollo.core.spi.Ordered;
import org.apache.commons.logging.Log;
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.web.reactive.function.client.WebClientCustomizer;
Expand All @@ -37,11 +36,15 @@ public interface ApolloClientWebClientCustomizerFactory extends Ordered {
* @param binder properties binder
* @param bindHandler properties binder Handler
* @param log deferred log
* @param bootstrapContext bootstrapContext
* @param bootstrapContext bootstrapContext (can be either
* org.springframework.boot.ConfigurableBootstrapContext for
* Spring Boot 3.x or
* org.springframework.boot.bootstrap.ConfigurableBootstrapContext
* for Spring Boot 4.x)
* @return WebClientCustomizer instance or null
*/
@Nullable
WebClientCustomizer createWebClientCustomizer(ApolloClientProperties apolloClientProperties,
Binder binder, BindHandler bindHandler, Log log,
ConfigurableBootstrapContext bootstrapContext);
Object bootstrapContext);
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import com.ctrip.framework.apollo.config.data.extension.initialize.ApolloClientExtensionInitializer;
import com.ctrip.framework.apollo.config.data.extension.properties.ApolloClientProperties;
import org.apache.commons.logging.Log;
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;
Expand All @@ -31,10 +30,10 @@ public class ApolloClientWebsocketExtensionInitializer implements ApolloClientEx

private final Log log;

private final ConfigurableBootstrapContext bootstrapContext;
private final Object bootstrapContext;

public ApolloClientWebsocketExtensionInitializer(DeferredLogFactory logFactory,
ConfigurableBootstrapContext bootstrapContext) {
Object bootstrapContext) {
this.log = logFactory.getLog(ApolloClientWebsocketExtensionInitializer.class);
this.bootstrapContext = bootstrapContext;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.ctrip.framework.apollo.Config;
import com.ctrip.framework.apollo.ConfigService;
import com.ctrip.framework.apollo.config.data.util.BootstrapRegistryHelper;
import com.ctrip.framework.apollo.config.data.util.Slf4jLogMessageFormatter;
import com.ctrip.framework.apollo.spring.config.ConfigPropertySource;
import com.ctrip.framework.apollo.spring.config.ConfigPropertySourceFactory;
Expand All @@ -26,8 +27,6 @@
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.logging.Log;
import org.springframework.boot.BootstrapRegistry.InstanceSupplier;
import org.springframework.boot.ConfigurableBootstrapContext;
import org.springframework.boot.context.config.ConfigData;
import org.springframework.boot.context.config.ConfigDataLoader;
import org.springframework.boot.context.config.ConfigDataLoaderContext;
Expand Down Expand Up @@ -55,22 +54,24 @@ public ApolloConfigDataLoader(DeferredLogFactory logFactory) {
@Override
public ConfigData load(ConfigDataLoaderContext context, ApolloConfigDataResource resource)
throws IOException, ConfigDataResourceNotFoundException {
ConfigurableBootstrapContext bootstrapContext = context.getBootstrapContext();
Binder binder = bootstrapContext.get(Binder.class);
Object bootstrapContext = BootstrapRegistryHelper.getBootstrapContext(context);
Binder binder = BootstrapRegistryHelper.get(bootstrapContext, Binder.class);
BindHandler bindHandler = this.getBindHandler(context);
bootstrapContext.registerIfAbsent(ApolloConfigDataLoaderInitializer.class, InstanceSupplier
.from(() -> new ApolloConfigDataLoaderInitializer(this.logFactory, binder, bindHandler,
bootstrapContext)));
ApolloConfigDataLoaderInitializer apolloConfigDataLoaderInitializer = bootstrapContext
.get(ApolloConfigDataLoaderInitializer.class);
BootstrapRegistryHelper.registerIfAbsentFromSupplier(bootstrapContext,
ApolloConfigDataLoaderInitializer.class,
() -> new ApolloConfigDataLoaderInitializer(this.logFactory, binder, bindHandler,
bootstrapContext));
ApolloConfigDataLoaderInitializer apolloConfigDataLoaderInitializer =
BootstrapRegistryHelper.get(bootstrapContext, ApolloConfigDataLoaderInitializer.class);
// init apollo client
List<PropertySource<?>> initialPropertySourceList = apolloConfigDataLoaderInitializer
.initApolloClient();
// load config
bootstrapContext.registerIfAbsent(ConfigPropertySourceFactory.class,
InstanceSupplier.from(() -> SpringInjector.getInstance(ConfigPropertySourceFactory.class)));
ConfigPropertySourceFactory configPropertySourceFactory = bootstrapContext
.get(ConfigPropertySourceFactory.class);
BootstrapRegistryHelper.registerIfAbsentFromSupplier(bootstrapContext,
ConfigPropertySourceFactory.class,
() -> SpringInjector.getInstance(ConfigPropertySourceFactory.class));
ConfigPropertySourceFactory configPropertySourceFactory =
BootstrapRegistryHelper.get(bootstrapContext, ConfigPropertySourceFactory.class);
String namespace = resource.getNamespace();
Config config = ConfigService.getConfig(namespace);
ConfigPropertySource configPropertySource = configPropertySourceFactory
Expand All @@ -83,7 +84,8 @@ public ConfigData load(ConfigDataLoaderContext context, ApolloConfigDataResource
}

private BindHandler getBindHandler(ConfigDataLoaderContext context) {
return context.getBootstrapContext().getOrElse(BindHandler.class, null);
Object bootstrapContext = BootstrapRegistryHelper.getBootstrapContext(context);
return BootstrapRegistryHelper.getOrElse(bootstrapContext, BindHandler.class, null);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import java.util.List;
import java.util.Map;
import org.apache.commons.logging.Log;
import org.springframework.boot.ConfigurableBootstrapContext;
import org.springframework.boot.context.properties.bind.BindHandler;
import org.springframework.boot.context.properties.bind.Bindable;
import org.springframework.boot.context.properties.bind.Binder;
Expand All @@ -54,11 +53,11 @@ class ApolloConfigDataLoaderInitializer {

private final BindHandler bindHandler;

private final ConfigurableBootstrapContext bootstrapContext;
private final Object bootstrapContext;

public ApolloConfigDataLoaderInitializer(DeferredLogFactory logFactory,
Binder binder, BindHandler bindHandler,
ConfigurableBootstrapContext bootstrapContext) {
Object bootstrapContext) {
this.logFactory = logFactory;
this.log = logFactory.getLog(ApolloConfigDataLoaderInitializer.class);
this.binder = binder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
*/
package com.ctrip.framework.apollo.config.data.listener;

import org.springframework.boot.BootstrapRegistry.InstanceSupplier;
import org.springframework.boot.ConfigurableBootstrapContext;
import com.ctrip.framework.apollo.config.data.util.BootstrapRegistryHelper;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.context.event.ApplicationStartingEvent;
import org.springframework.context.ApplicationListener;
Expand All @@ -30,8 +29,8 @@ public class ApolloSpringApplicationRegisterListener implements

@Override
public void onApplicationEvent(ApplicationStartingEvent event) {
ConfigurableBootstrapContext bootstrapContext = event.getBootstrapContext();
bootstrapContext.registerIfAbsent(SpringApplication.class,
InstanceSupplier.of(event.getSpringApplication()));
Object bootstrapContext = BootstrapRegistryHelper.getBootstrapContext(event);
BootstrapRegistryHelper.registerIfAbsent(bootstrapContext, SpringApplication.class,
event.getSpringApplication());
}
}
Loading