首页 > 解决方案 > 如何在没有 PropertySource 的情况下加载 SpringBoot application.properties

问题描述

我正在构建一个可以在有/没有 Spring 的情况下使用的框架。所以,我不能使用 @PropertySource 注释。

考虑到所有可能的变化,我如何才能准确地知道 application.properties 路径。例如,用户使用 --spring.config.location 更改了默认路径

是否有任何 Spring 运行时变量可以让我获得此路径?

标签: javaspring-boot

解决方案


只需注入环境

@Autowired
private Environment environment;

它包含一个propertySourceList,其中包含所有属性源:)

也许这对您来说也很有趣:


推荐阅读