Source Address: Https://github.com/roncoo/spring-boot-demo
I. The order in which the configuration files are effective, the values are overwritten:
1. @TestPropertySource annotations
2. Command-line arguments
3. Java System Properties (System.getproperties ())
4. Operating system Environment variables
5. Only the attributes contained in the random.* will produce a randomvaluepropertysource
6. Application configuration file (Application.properties, including YAML and profile variables) outside the packaged jar
7. Application configuration file (Application.properties, including YAML and profile variables) within the packaged jar
8. @propertysource annotations on the @configuration class
9. Default properties (specified with springapplication.setdefaultproperties)
Two Configure random values
Roncoo.secret=${random.value}
Roncoo.number=${random.int}
Roncoo.bignumber=${random.long}
Roncoo.number.less.than.ten=${random.int (10)}
RONCOO.NUMBER.IN.RANGE=${RANDOM.INT[1024,65536]}
Read using annotations: @Value (Value = "${roncoo.secret}")
Note: The yellow dot hint is to prompt for configuration metadata, you can not configure
Three Property placeholder
When values in Application.properties are used, they are filtered by the presence of environment, so you can refer to previously defined values (for example, System Properties).
Roncoo.name=www.roncoo.com
Roncoo.desc=${roncoo.name} is a domain name
Four Application properties file, sorted by priority, high position will cover low
1. A/config subdirectory under the current directory
2. Current directory
3. A/config bag under a classpath
4. Classpath root Path (root)
This list is sorted by priority (the high position in the list will have a low coverage position)
Five. Introduction to configuring Application ports and other configurations
#端口配置:
server.port=8090
#时间格式化
SPRING.JACKSON.DATE-FORMAT=YYYY-MM-DD HH:mm:ss
#时区设置
Spring.jackson.time-zone=asia/chongqing
Six. Use Yaml instead of properties
Note: Add a space after the colon
Project Source Address
Follow me:
Spring Boot base 3-configuration file Details: properties and Yaml