您好,登錄后才能下訂單哦!
本篇內容主要講解“SpringBoot的配置優先級是什么”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學習“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命令設置環境變量,也能按照期望的方式工作:
到此,相信大家對“SpringBoot的配置優先級是什么”有了更深的了解,不妨來實際操作一番吧!這里是億速云網站,更多相關內容可以進入相關頻道進行查詢,關注我們,繼續學習!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。