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

同一个配置项,在不同命名空间时,优先级问题。 #235

Closed
quanlianliu2023 opened this issue Jul 31, 2023 · 3 comments
Closed

Comments

@quanlianliu2023
Copy link

你好:

有 2 个命名空间,application 与 application2,根据 apollo 官方说明,当引入 application2 时应该会默认覆盖 application 的配置项,
目前是无效的。

image

        public TestController(ITokenService tokenService, IConfiguration configuration, IOptionsMonitor<LiuXueOptions> options)
        {
            _tokenService = tokenService;
            _secret = options.CurrentValue.LiuXueAdminAPISecret!;
            _configuration = configuration;
        }


        public IActionResult Index()
        {
            var env = _configuration["Env"];

            // "Namespaces": [ "application2", "application" ]
            // "Namespaces": [ "application", "application2" ]

            // 始终返回:env: DEV
            // 即:application2 的配置,无法覆盖默认 application 的配置项的值。

            return Content("env: " + env);
        }
@pengweiqhca
Copy link
Contributor

调试时看看_configuration的Providers属性值的顺序,以及相应的两个Provider的Data属性值

@quanlianliu2023
Copy link
Author

quanlianliu2023 commented Jul 31, 2023

image

你好,目前配置中心注册了 3 个 provider,第1个 provider 值 为 UAT,第 3 个 provider 值为 DEV

无论是否调整 namespaces 顺序,provider 始终都是如此。请看图。

  "Apollo": {
    "AppId": "",
    "Secret": "",
    "MetaServer": "",
    "Namespaces": [ "application", "application.json", "application2" ]
  }

@quanlianliu2023
Copy link
Author

image
感谢,问题应该排查到了,这里在添加 apollo 时,又进行 .AddDefault() 添加了默认的命名空间导致的。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants