Spring Boot学习--资源配置

本文深入探讨Spring Boot的外部化配置,包括properties和YAML文件、环境变量、命令行参数的使用。通过@Value和@ConfigurationProperties注解获取配置信息。示例展示了如何从配置文件读取、覆盖以及通过命令行和SPRING_APPLICATION_JSON传递配置。还提及了JNDI方式,但未展开讲解。最后提到了多环境配置文件的管理。
摘要由CSDN通过智能技术生成

这部分内容主要对应官网文档的第24部分Externalized Configuration,我也不知道怎么来准确翻译这个东西。这块涉及到的是配置文件中的环境变量的相关内容。

按照官方的意思是,Spring Boot提供了多种换取环境变量或者配置信息的方式。如properties 文件YAML文件,环境变量和客户端指令等。你可以通过@Value注解和@ConfigurationProperties来获取这些信息。

废话少说,我们来看下具体内容,优先级依次降低的:


 1. Devtools global settings properties on your home directory (~/.spring-boot-devtools.properties when devtools is active).
 2. @TestPropertySource annotations on your tests.
 3. @SpringBootTest#properties annotation attribute on your tests.
 4. Command line arguments.
 5. Properties from SPRING_APPLICATION_JSON (inline JSON embedded in an environment variable or system property)
 6. ServletConfig init parameters.
 7. ServletContext init parameters.
 8. JNDI attributes from java:comp/env.
 9. Java System properties (System.getProperties()).
 10. OS environment variables.
 11. A RandomValuePropertySource that only has properties in random.*.
 12. Profile-specific application properties outside of your packaged jar (application-{profile}.properties and YAML variants)
 13. Profile-specific application properties packa
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值