Source Address: Https://github.com/roncoo/spring-boot-demo
I. Benefits of multi-environment configuration:
1. Different environment configuration can be configured with different parameters
2. Easy to deploy, improve efficiency, reduce errors
Two. Properties Multi-environment configuration
1. Configure activation options
Spring.profiles.active=dev
2. Add additional Profiles
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
Four Comparison of two configuration methods
1. Properties configuration Multi-environment, need to add multiple configuration files, Yaml only need one accessory file
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.
Five How to use
Java-jar Myapp.jar--spring.profiles.active=dev
Project Source Address
Follow me:
Spring Boot base 4-Configuration Files-Multi-environment configuration