@ConfigurationProperties(prefix = "xxx")的值取出为空

当你在使用Spring Boot 时候,

如果发现引用的@ConfigurationProperties(prefix = “xxx”)的属性值取出为空

那么原因很有可能是下面这个原因:

尽管我们定义某些变量时候习惯用xx_xx来命名,

但是在定义这个yml配置文件时,

千万要注意,这里文件里定义的属性值一定不可以带有下划线符号'_',

否则通过

@Component
@ConfigurationProperties(prefix = "easemob")

注解类所获取的属性值会为空。

错误用法
application-dev.yml

easemob:
  client_Id: YXA6RgFecP8gEea***********
  client_Secret: YXA6WkMEerwml*********

正确用法
application-dev.yml

easemob:
  clientId: YXA6RgFecP8gEea***********
  clientSecret: YXA6WkMEerwml*********

猜你喜欢

转载自blog.csdn.net/hadues/article/details/79123645