- Mastering Spring Boot 2.0
- Dinesh Rajput
- 422字
- 2021-06-25 21:29:15
Order of evaluation for overridden properties
Let's see the following order of evaluation for overridden properties:
- Defined properties for the Devtools global settings in your home directory
- Defined properties for @TestPropertySource annotations on your tests
- Properties as command-line arguments
- Defined properties from SPRING_APPLICATION_JSON
- The properties with ServletConfig init parameters
- The properties with ServletContext init parameters
- JNDI attributes from java:comp/env
- Java system properties
- OS environment variables
- Property file(s)—including application.properties and its YAML variant
This preceding list is in order of precedence. That means if you set any property from a source higher in the list, Spring will override the same property defined in the source lower in the list. The test environment and command-line arguments override properties from any other property source.
Let's see the following order of evolution of the properties file and YAML variants:
- A RandomValuePropertySource class that injects properties with random value into configuration file define as random.*
- Profile-specific application properties outside of your packaged JAR, that is, in the /config subdirectory of the directory from which the application is run (application-{profile}.properties and YAML variants)
Select a profile by executing the JAR with param Dspring.profiles.active=dev or setting the property spring.profiles.active=dev.
- Profile-specific application properties outside of your packaged JAR but in a directory from which the application is run (application-{profile}.properties and YAML variants)
- Profile-specific application properties packaged inside your JAR but in a package named config (application-{profile}.properties and YAML variants)
- Profile-specific application properties packaged inside your JAR but at the root of the classpath (application-{profile}.properties and YAML variants)
- Application properties outside of your packaged JAR, that is, in the /config subdirectory of the directory from which the application is run (application.properties and YAML variants)
- Application properties outside of your packaged JAR but in a directory from which the application is run (application.properties and YAML variants)
- Application properties packaged inside your JAR but in a package named config (application.properties and YAML variants)
- Application properties packaged inside your JAR but at the root of the classpath (application.properties and YAML variants)
- @PropertySource annotations on your @Configuration classes
- Default properties (specified using SpringApplication.setDefaultProperties)
According to the order of precedence, if you set any properties in a profile-specific application-{profile}.properties will override the same properties set in an application.properties file at the same location as the application-{profile}.properties file.
Again, this list is in order of precedence. That is, an application.properties file in a /config subdirectory will override the same properties set in a application.properties file in the application's classpath.
Let's see how to customize the name of the application property file (application.properties).
- 和秋葉一起學(xué):秒懂Excel(全彩版)
- Office 2019高效辦公三合一從入門到精通(視頻自學(xué)版)
- Docker技術(shù)入門與實(shí)戰(zhàn)
- WPS Office商務(wù)辦公從新手到高手
- Word Excel PPT 三合一 效率手冊(cè):早做完,不加班
- 快·易·通:2天學(xué)會(huì)Word/Excel綜合辦公應(yīng)用(2016版)
- Excel 2016數(shù)據(jù)透視表從入門到精通
- 巧學(xué)巧用Excel函數(shù):掌握核心技能,秒變數(shù)據(jù)分析高手
- 零基礎(chǔ)學(xué)游戲UI設(shè)計(jì)
- Excel公式與函數(shù)大辭典
- Intuit QuickBooks Enterprise Edition 12.0 Cookbook for Experts
- 30天精學(xué)Excel:從菜鳥到數(shù)據(jù)分析高手
- 新編PowerPoint 2016從入門到精通
- Word/Excel/PPT辦公應(yīng)用從入門到精通
- Word Excel PPT PS 移動(dòng)辦公5合1(全5冊(cè))