Spring Boot Externalized Configuration

https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html

 

Externalized Configuration

Spring Boot lets you externalize your configuration so that you can work with the same application code in different environments. You can use properties files, YAML files, environment variables, and command-line arguments to externalize configuration. Property values can be injected directly into your beans by using the @Value annotation, accessed through Spring’s Environment abstraction, or be bound to structured objects through @ConfigurationProperties.

Spring Boot uses a very particular PropertySource order that is designed to allow sensible overriding of values. Properties are considered in the following order:

  1. Devtools global settings properties on your home directory (~/.spring-boot-devtools.properties when devtools is active).
  2. @TestPropertySource annotations on your tests.
  3. properties attribute on your tests. Available on @SpringBootTest and the test annotations for testing a particular slice of your application.
  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. RandomValuePropertySource that has properties only in random.*.
  12. Profile-specific application properties outside of your packaged jar (application-{profile}.properties and YAML variants).
  13. Profile-specific application properties packaged inside your jar (application-{profile}.properties and YAML variants).
  14. Application properties outside of your packaged jar (application.properties and YAML variants).
  15. Application properties packaged inside your jar (application.properties and YAML variants).
  16. @PropertySource annotations on your @Configuration classes.
  17. Default properties (specified by setting SpringApplication.setDefaultProperties). 

转载于:https://www.cnblogs.com/merseyalma/p/10276386.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Spring Boot的主要内容包括以下几个方面: 1. 自动配置(Auto-configuration):Spring Boot通过自动配置来简化应用程序的配置过程。它根据应用程序的依赖关系自动配置Spring和第三方库,减少了手动配置的工作量。 2. 起步依赖(Starter Dependencies):Spring Boot提供了一系列的起步依赖,它们是预先配置好的依赖项集合,可以快速启动一个特定类型的应用程序。起步依赖包含了所需的所有依赖项,使得开发者可以更加方便地构建应用程序。 3. 命令行界面(Command-line Interface):Spring Boot提供了一个命令行界面,可以在命令行中运行Spring Boot应用程序。开发者可以使用命令行界面来快速创建、运行和调试应用程序。 4. Actuator:Actuator是Spring Boot的一个重要特性,它提供了对应用程序的监控和管理功能。通过Actuator,开发者可以查看应用程序的健康状况、性能指标、日志信息等,并且可以进行动态修改配置等操作。 5. 外部化配置(Externalized Configuration):Spring Boot支持将应用程序的配置信息外部化,可以使用属性文件、环境变量、命令行参数等方式来配置应用程序。这样可以使得应用程序的配置更加灵活和易于管理。 6. Spring Boot Starter项目:Spring Boot Starter是一种特殊的起步依赖,它提供了一组相关的依赖项,用于快速启动一个特定类型的项目。例如,Spring Boot提供了Spring Boot Starter Web项目,用于快速启动一个Web应用程序。 以上是Spring Boot的主要内容,它们使得开发者可以更加方便地构建、配置和管理Spring Boot应用程序。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值