Skip to content

Commit

Permalink
Merge #1246 (#1251)
Browse files Browse the repository at this point in the history
* init interface class canonical name to avoid multi reflection

* update 3.21.0-SNAPSHOT

* avoid SofaConfigSourceSupportListener duplicate register configs (#1246)

* format

---------

Co-authored-by: 致节 <hzj266771@antgroup.com>
  • Loading branch information
HzjNeverStop and 致节 authored Sep 28, 2023
1 parent efbf96c commit d03eeea
Showing 1 changed file with 30 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.util.StringUtils;

import java.util.concurrent.atomic.AtomicBoolean;

/**
* add a config source based on {@link ConfigurableEnvironment}
* @author huzijie
Expand All @@ -34,32 +36,40 @@ public class SofaConfigSourceSupportListener
implements
ApplicationListener<ApplicationEnvironmentPreparedEvent>,
Ordered {
private static final int SOFA_BOOT_CONFIG_SOURCE_ORDER = ApplicationListenerOrderConstants.SOFA_CONFIG_SOURCE_SUPPORT_LISTENER_ORDER;
private static final int SOFA_BOOT_CONFIG_SOURCE_ORDER = ApplicationListenerOrderConstants.SOFA_CONFIG_SOURCE_SUPPORT_LISTENER_ORDER;

private final AtomicBoolean registered = new AtomicBoolean();

@Override
public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
ConfigurableEnvironment environment = event.getEnvironment();
SofaConfigs.addConfigSource(new AbstractConfigSource() {
@Override
public int getOrder() {
return SOFA_BOOT_CONFIG_SOURCE_ORDER;
}
registerSofaConfigs(event.getEnvironment());
}

private void registerSofaConfigs(ConfigurableEnvironment environment) {
if (registered.compareAndSet(false, true)) {
SofaConfigs.addConfigSource(new AbstractConfigSource() {

@Override
public int getOrder() {
return SOFA_BOOT_CONFIG_SOURCE_ORDER;
}

@Override
public String getName() {
return "SOFABootEnv";
}
@Override
public String getName() {
return "SOFABootEnv";
}

@Override
public String doGetConfig(String key) {
return environment.getProperty(key);
}
@Override
public String doGetConfig(String key) {
return environment.getProperty(key);
}

@Override
public boolean hasKey(String key) {
return !StringUtils.isEmpty(environment.getProperty(key));
}
});
@Override
public boolean hasKey(String key) {
return !StringUtils.isEmpty(environment.getProperty(key));
}
});
}
}

@Override
Expand Down

0 comments on commit d03eeea

Please sign in to comment.