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

@NacosConfigurationProperties注解中动态配置优先级太低被系统配置覆盖 #323

Closed
nailcui opened this issue Jan 31, 2024 · 2 comments

Comments

@nailcui
Copy link

nailcui commented Jan 31, 2024

Nacos 配置信息:

url: localhost:8080
username: nacos

复现代码:

@Data
@Configuration
@NacosConfigurationProperties(groupId = "production", dataId = "app-config.yaml", autoRefreshed = true)
public class MysqlConfiguration {

  private String url;

  private String username;

  @PostConstruct
  public void init() {
    System.out.println("mysql url : " + url);  # 输出: localhost:8080
    System.out.println("mysql name: " + username);  # 输出我的计算机名称: Dingyu.Cui
  }

}

在上面代码中,输出的配置信息不是 nacos 里的配置,而是我的本地电脑信息。

代码中,指定的配置文件优先级低于 systemPropertiessystemEnvironment
33fcd5dc29bde42a49a948a56c046c94

在这里我认为应该先以指定的 nacos 配置文件为准,以系统的环境信息为兜底更为合理

我将提交 pr 来修复这个问题

@ilaotan
Copy link

ilaotan commented Feb 23, 2024

你了解下springboot的配置文件加载顺序,就是系统配置最高啊。

@nailcui nailcui closed this as completed Mar 6, 2024
@sN0wpeak
Copy link

sN0wpeak commented Apr 7, 2024

所以说这是预期的行为吗?用 NacosConfigurationProperties注解时,可以被本地的环境变量覆盖?

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

3 participants