Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does it support dynamic configuration addition? #3900

Open
youngledo opened this issue Nov 21, 2024 · 2 comments
Open

Does it support dynamic configuration addition? #3900

youngledo opened this issue Nov 21, 2024 · 2 comments
Labels
area/nacos spring cloud alibaba nacos kind/question

Comments

@youngledo
Copy link

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.
image

不知道nacos是否有对应的扩展,如果没有是不是只能通过Spring底层的方法加载?
I don't know if Nacos has corresponding extensions. If not, can it only be loaded through the underlying methods of Spring?

@yuluo-yx yuluo-yx added kind/question area/nacos spring cloud alibaba nacos labels Nov 21, 2024
@yuluo-yx
Copy link
Collaborator

啥意思?没理解

@youngledo
Copy link
Author

youngledo commented Nov 21, 2024

上面的扩展配置(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来达到目的。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/nacos spring cloud alibaba nacos kind/question
Projects
None yet
Development

No branches or pull requests

2 participants