情景:因为不可能所有的属性都放在全局文件(SpringBoot项目使用一个全局的配置文件application.properties或者是application.yml)中

所以需要把一些跟springboot无关的东西放在其他文件,用 @PropertySource:加载指定的配置文件;
直接用@PropertySource读取不到值,原因在于@PropertySource需要和@propertyConfiguration一起使用
@Component
@ConfigurationProperties(prefix = "person")

最终要注解内容有:

@Component
@ConfigurationProperties(prefix = "person")
@PropertySource(value={"classpath:/person.properties"})


详情链接

相关文章:

  • 2021-08-16
  • 2022-12-23
  • 2021-11-18
  • 2021-09-23
  • 2021-11-18
  • 2022-12-23
  • 2022-02-09
  • 2022-03-02
猜你喜欢
  • 2021-04-10
  • 2022-03-04
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案