I. benefits of multi-environment configuration:
1. different environment configuration can be configured with different parameters ~
2. Easy to deploy, improve efficiency, reduce error ~
Two. Properties Multi-environment configuration
1. Configure activation options
Spring.profiles.active=dev
2. Add additional Profiles
Application.properties:
#激活哪一个环境的配置文件spring. profiles.active=dev# Public configuration Spring.jackson.date-format=yyyy-mm-dd HH:MM:SS:
You can also create an active environment when running
--spring.profiles.active=prd
three . YAML Multi-environment configuration
1. Configure activation options
Spring: Profiles: Active:dev
2. Add three short lines in the configuration file to distinguish between the two English states
---Spring: profiles:dev
Application.yml
#激活哪一个环境的配置文件Spring: Profiles: active:prd# public configuration Spring: Jackson: Date-format : Yyyy-mm-dd HH:mm:ss---Spring: profiles:devserver: port:8081---Spring: profiles:testserver: port:8082---Spring: profiles:prdserver: port:8083
This situation is an error: Duplicate key:spring
The correct configuration:
#激活哪一个环境的配置文件 # Public configuration spring: profiles: active:prd Jackson: date-format:yyyy-mm-dd hh:mm: SS---Spring: profiles:devserver: port:8081---Spring: profiles:testserver: port:8082---Spring: profiles:prdserver: port:8083
Four . Comparison of two configuration methods
1. Properties configuration Multi-environment, need to add multiple configuration files, Yaml only need one accessory file
The yml file itself has the ability to differentiate between different environments
2. The difference in writing format, Yaml relatively concise, elegant
3. Yaml's disadvantage: it cannot be loaded by @propertysource annotations. If you need to load values using @propertysource annotations, use the properties file.
True, or like the configuration form of properties, yml form of elegance? No feeling ~ haha ~
Spring Boot configuration file-Multi-environment configuration