SpringBoot里的官方文档叫做Externalized Configuration:

优先级依次如下:

(1) Devtools global settings properties in the $HOME/.config/spring-boot folder 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) A 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. Please note that such property sources are not added to the Environment until the application context is being refreshed. This is too late to configure certain properties such as logging.* and spring.main.* which are read before refresh begins.

(17) Default properties (specified by setting SpringApplication.setDefaultProperties).

做个实验,在run as configuration里,program argument设置为server.port=8001,

Environment环境变量设置为server.port=8002.

在SpringBoot项目内部的Application.properties文件设置成8000:

最后运行时,生效的端口是环境变量设置进去的8002:


在shell里使用set命令设置环境变量,也能按照期望的方式工作:


要获取更多Jerry的原创文章,请关注公众号"汪子熙":

SpringBoot的配置优先级,一个具体的练习例子相关推荐

  1. 一个由于springboot自动配置所产生的问题的解决

    一个由于springboot自动配置所产生的问题的解决 参考文章: (1)一个由于springboot自动配置所产生的问题的解决 (2)https://www.cnblogs.com/hlhdidi/ ...

  2. 【springboot】配置

    配置文件 SpringBoot使用一个全局的配置文件,配置文件名是固定的: •application.properties •application.yml 配置文件的作用:修改SpringBoot自 ...

  3. SpringBoot的配置详解application

    SpringBoot的配置文件application有两种文件格式,两种配置的内容是一致的,只是格式不一致. 1.application.properties 2.application.yml或者a ...

  4. 补习系列(10)-springboot 之配置读取

    目录 简介 一.配置样例 二.如何注入配置 1. 缺省配置文件 2. 使用注解 3. 启动参数 还有.. 三.如何读取配置 @Value 注解 Environment 接口 @Configuratio ...

  5. SpringBoot控制配置类加载顺序

    1.@Configuration配置被加载进容器的方式大体上可分为3种 手动:构建ApplicationContext时由构建者手动传入,可手动控制顺序. 自动1:被@ComponentScan自动扫 ...

  6. SpringBoot 全局配置和静态资源配置

    1.配置文件 SpringBoot使用一个全局的配置文件,配置文件名是固定的: application.properties application.yml 配置文件的作用:修改SpringBoot自 ...

  7. 【SpringBoot入门】SpringBoot的配置

    SpringBoot的配置文件 一.SpringBoot配置文件分类 二.yaml 概述 三.多环境配置 四.@Value 和 @ConfigurationProperties 五.总结 一.Spri ...

  8. 跟我学SpringBoot之配置常见用法

    只需低头努力,剩下的交给时光,时间会公平地帮你处理一切 配置基本用法 application.yml book:name: "Java" @Value注解可以直接取配置的值 @Re ...

  9. springboot+mybatis+thymeleaf学习一个简单的管理系统

    在淘宝上买的课程的一个例子,看了视频,抄了一遍代码,那时候刚开始学springboot,所以感觉没什么用,然后就又学习了一段时间.最近回想起来有这样的一个系统符合我现阶段的学习程度,然后就又写了一遍. ...

最新文章

  1. Google VC投资SDN初创公司Plexxi
  2. 廖雪峰为你无门槛讲述高并发那些事
  3. GoogleReader的Likes操作数据如何获取?
  4. 【jetson nano】 aarch64安装pycharm pytorch cuda
  5. 用行为树的方式思考:任务系统设计
  6. 编写高质量代码:改善Java程序的151个建议(第4章:字符串___建议52~55)
  7. form的enctype和action
  8. 奇瑞a3中控按键图解_实拍奇瑞全新瑞虎e 十万元级纯电SUV新选择
  9. 从Dataframe训练数据,构造可迭代训练的batch数据
  10. 拼多多回应驰伟插座起诉:积极应诉 希望其莫充当电商“二选一”插头
  11. linux钩子函数和回调函数,Linux Kernel 学习笔记10:hook函数
  12. 关于C++的建议,仅仅为了规范代码(二)
  13. 断网问题解决【值得一记】
  14. 统计图源代码_openlayers4 入门开发系列结合 echarts4 实现统计图(附源码下载)
  15. python中的实用模块_python中的常用模块
  16. java集合uml_Java开源UML建模集合
  17. 利用xshell通过公钥私钥连接linux服务器
  18. OpenPose安装(gtx1650+cuda10.1+cudnn7.6.0+anaconda3)
  19. 配置光盘镜像YUM源和阿里YUM源(纯干货,建议收藏)
  20. BoundsChecker的使用

热门文章

  1. 重写Gallery中方法去处理Gallery滑动时的惯性
  2. Java Properties的使用
  3. Entity Framework 普通操作(复习用)——感觉有点不对,需要撸代码验证
  4. 关于splice()方法,slice() 、split()方法讲解,reverse()方法、replace()方法
  5. 杂谈3之English
  6. CODE[VS]-求和-整数处理-天梯青铜
  7. eclipse+webservice开发实例
  8. 如何在Django1.6结合Python3.3版本中使用MySql
  9. 项目-团队-技术-个人 (团队建设篇)
  10. SonarQube6.2源码解析(四)