Spring boot enables you to use different configuration variables in different environments (such as development, test, and production environments) by configuring multiple profiles in the APPLICATION.YML configuration file.
The configuration is as follows (content in APPLICATION.YML):
Server:
port:8082
# The default profile is dev, and other environments use different profiles by specifying startup parameters, such as:
# test Environment: Java-jar My-spring-boot.jar--spring.profiles.active=test
# production environment: Java-jar My-spring-boot.jar-- Spring.profiles.active=prod
Spring:
profiles:
active:dev
---
# development environment Configuration
Spring:
Profiles:dev
MySQL:
ipport:localhost:3306
---
# test environment Configuration
Spring:
profiles:test
MySQL:
ipport:192.168.0.12:8066
---
# production environment Configuration
Spring:
profiles:prod
MySQL:
ipport:192.168.0.13:8066
How to use:
Use different profiles by specifying the startup parameters, such as:
# test environment: Java-jar My-spring-boot.jar--spring.profiles.active=test
# production environment: Java-jar My-spring-boot.jar--spring.profiles.active=prod
Source code Address: Https://github.com/xujijun/my-spring-boot