java - 如何找到spring加载的application.yml的位置?
问题描述
为了配置 Spring Boot 应用程序,我可以application.yml
通过将文件放置在 Spring 扫描此类文件的位置之一(./config/、cwd、classpath:config/、classpath root)来控制加载哪个配置/属性文件(比方说) )。spring.config.location
我还可以使用 CLI ( ) 或环境变量指向特定位置。
如何找出运行时最终从何处加载属性文件?我想检查用户是否指定/使用了他自己的配置文件,或者是否使用了提供的配置文件。
我正在使用 spring 5.2.2 和 springboot 2.2.2。
解决方案
我认为在应用程序启动后不可能找到它。
但是,您可以在启动期间检查“org.springframework.boot”的调试日志输出。
要快速启用调试日志到控制台,您可以--debug
在命令行或debug=true
application.yml 中运行 spring boot 应用程序。Spring Boot 找到的配置文件应该在前几行。
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.2.6.RELEASE)
2020-04-08 15:05:22.736 INFO 19079 --- [ main] com.example.demo.DemoApplication : Starting DemoApplication on Dwalin with PID 19079 (/home/geertp/repos/github.com/greyfairer/spring-boot-test/demo/target/classes started by geertp in /home/geertp/repos/github.com/greyfairer/spring-boot-test/demo)
2020-04-08 15:05:22.736 INFO 19079 --- [ main] com.example.demo.DemoApplication : No active profile set, falling back to default profiles: default
2020-04-08 15:05:22.737 DEBUG 19079 --- [ main] o.s.boot.SpringApplication : Loading source class com.example.demo.DemoApplication
2020-04-08 15:05:22.765 DEBUG 19079 --- [ main] o.s.b.c.c.ConfigFileApplicationListener : Loaded config file 'file:/home/geertp/repos/github.com/greyfairer/spring-boot-test/demo/target/classes/application.yml' (classpath:/application.yml)
推荐阅读
- android - 带有 RxJava3 的房间
- html - 我可以根据特定的数组名动态检查当前的单选按钮数组吗?
- javascript - 如何按对象键和值过滤对象?
- react-native - React Native,不理解调用firebase的异步函数流
- node.js - 等待循环 NodeJS 中的每个元素执行 findOneAndDelete 方法
- flutter - 我无法在 Dart 中将调整大小的 Image 对象转换为 Base64 字符串
- firebase - 颤振谷歌服务插件
- flutter - 是否可以向停靠的浮动操作按钮添加填充或边距?
- javascript - 未捕获的语法错误:意外的标记“<”
- python - 从网格位置获取 Tkinter Checkbutton 值