sch*_*uzz 1 java configuration spring spring-boot
为了配置 Spring Boot 应用程序,我可以application.yml通过将文件放置在 spring 扫描此类文件的位置之一(./config/、cwd、classpath:config/、classpath root)来控制加载哪个配置/属性文件(比方说) )。我还可以使用 CLI ( ) 或环境变量指向特定位置spring.config.location。
如何找出运行时属性文件最终从何处加载?我希望检查用户是否指定/使用了他自己的配置文件或者是否使用了提供的配置文件。
我正在使用 spring 5.2.2 和 springboot 2.2.2。
我认为在应用程序启动后不可能找到它。
但是,您可以在启动过程中检查“org.springframework.boot”的调试日志输出。
--debug要快速启用控制台的调试日志记录,您可以在命令行或application.yml 中运行 spring boot 应用程序debug=true。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)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13276 次 |
| 最近记录: |