Sub-environment configuration
Sanfeng soft Zhang Sanfeng
Configuration file
In normal development, there are the following three configuration file environments, which means that different configuration files are used at different stages. If it is particularly troublesome to change a configuration file frequently, what should be done?
application-dev.properties: development environment
application-test.properties: test environment
application-prod.properties: production environment
First create the above three configuration files.The name specification must be the name of the main configuration file followed by-plus the name defined by yourself.The name behind it is self-made and does not need to be the same as mine.
Then in the main configuration file, add such a line, and the following value writes the part of the configuration file that you just created. At this time, the configuration file uses the content in dev.properties
Profile configuration multiple environments
How SpringBoot uses Profile to configure multi-environment support.
Profile is Spring's support for different configuration functions for different environments. It can quickly switch environments by activating, specifying parameters, etc.
1. Multi-profile file format:
-格式:application-{profile}.properties。
application-dev.properties、application-properties
2. Multi-profile document block mode
3. Activation method:
-Command line: --spring.profiles.active=dev
-Configuration file: spring.profiles.active=dev
-jvm参数:-Dspring.profiles.active=dev
yml支持多文档块的方式:
server:
port: 8888
spring:
profiles:
active: dev
---
server:
port: 8083
spring:
profiles: dev
---
server:
port: 8084
spring:
profiles: prod
There is also a way to set activation by specifying the activated configuration file in java -jar.