【问题标题】:getting Could not resolve placeholder while reading yml values in spring boot在 Spring Boot 中读取 yml 值时无法解析占位符
【发布时间】:2022-01-29 14:33:57
【问题描述】:

我正在使用 spring boot 并在我的 application.yml 中使用这个值

config:
  username: abc
  password: xyz

在我的课堂上,我就是这样使用它的 -

@Value("${config.username}")
    private String username;

我收到以下错误 -

Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'config.username' in value "${config.username}"

但是,如果我在 application.yml 文件中使用它,它就可以工作。你能告诉我我在这里做错了什么吗?

config.username: abc
config.password: xyz

【问题讨论】:

  • 用@Component 注释类。

标签: spring-boot yaml


【解决方案1】:

检查您的占位符是 Tab 还是 Space ?确保 yml 文件中没有 Tab。

【讨论】:

  • 也尝试了空格。我也用验证器验证了我的 yml,但仍然没有运气。 :(yamllint.com
猜你喜欢
  • 2018-02-20
  • 2019-04-04
  • 2018-06-17
  • 2016-01-20
  • 1970-01-01
  • 1970-01-01
  • 2016-12-25
  • 1970-01-01
  • 2016-10-21
相关资源
最近更新 更多