java - 如何在没有 PropertySource 的情况下加载 SpringBoot application.properties
问题描述
我正在构建一个可以在有/没有 Spring 的情况下使用的框架。所以,我不能使用 @PropertySource 注释。
考虑到所有可能的变化,我如何才能准确地知道 application.properties 路径。例如,用户使用 --spring.config.location 更改了默认路径
是否有任何 Spring 运行时变量可以让我获得此路径?
解决方案
只需注入环境
@Autowired
private Environment environment;
它包含一个propertySourceList,其中包含所有属性源:)
也许这对您来说也很有趣:
推荐阅读
- r - 如何自动补全数据集缺失的信息?
- android - 无法访问远程 .apk 文件
- c - 从多个 C 文件生成单个 C 文件
- flutter - 如何将桌面应用程序发布到另一台计算机?
- nginx - 除非给出特定的标头值,否则限制对特定端点的访问
- ckfinder - alpine 和 ckfinder 错误
- volume - Cloudstack:无法将卷数据附加到 VM Nas12U41
- c - OpenGL中的对象移动
- git - 如何在不删除 yaml 管道的情况下使用 azure devOps 管道在 azure repos 中自动将代码从 master 拉取到 fork
- c++ - 在使用 C++ 时返回非 void 的函数中没有返回语句