Open youngledo opened 1 day ago
啥意思?没理解
上面的扩展配置(extension-configs)是写死的,某些时候dataId是在启动时通过环境变量注入的(配置还是在nacos中),这样就得通过代码的形式动态增加。
@Configuration
public class McNacosBootstrapConfiguration {
private static final String APP_CODE_KEY = "application.code";
@Bean
public NacosConfigManager nacosConfigManager(NacosConfigProperties nacosConfigProperties, Environment environment) {
// 动态加载配置
String codeValue = environment.getProperty(APP_CODE_KEY);
if (codeValue != null && !codeValue.trim().isEmpty()) {
for (String code : codeValue.split(",")) {
nacosConfigProperties.getExtensionConfigs().add(
new NacosConfigProperties.Config("abc" + code + ".properties", "multi", true)
);
}
}
return new NacosConfigManager(nacosConfigProperties);
}
}
发现可以覆盖NacosConfigManager
来达到目的。
Which Component Nacos Config
Describe what problem you have encountered 支持动态添加配置的扩展吗?比如在代码中对扩展配置添加新的配置,而不是写死在yaml中。 Does it support dynamic configuration addition? For example, adding new configurations to the extension configuration in the code instead of writing them in YAML.
不知道nacos是否有对应的扩展,如果没有是不是只能通过Spring底层的方法加载? I don't know if Nacos has corresponding extensions. If not, can it only be loaded through the underlying methods of Spring?