日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

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

發布時間:2023/12/19 javascript 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 SpringBoot的配置优先级,一个具体的练习例子 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

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的配置优先级,一个具体的练习例子的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。