spring multi-file configuration:
1. Properties file
2. YAML file
1. Properties file
In Spring Boot, the file name configured by multiple environments needs to meet application-{profile}.
The format of properties, where {profile} corresponds to your environment identifier, as shown below.
• application-dev.properties: Development environment.
• application-test.properties: Test environment.
• application-prod.properties: Production environment.
As for which configuration file will be loaded, it needs to be passed in the app on.properties file
The spring.profiles.active property is set, and its value corresponds to the {profile} value in the configuration file. like
spring.profiles.active = test will load the application-test.properties configuration
File content.
2. YAML file
server: port: 8080 # The default profile is dev. Other environments use different profiles by specifying startup parameters, such as: # Test environment: java -jar xxx.jar --spring.profiles.active=test # Production environment: java -jar xxx.jar --spring.profiles.active=prod spring: profiles: active: dev #The following line must not be missing, distinguish different configurations, and must be three characters "-"---# Development environment configuration spring: profiles: dev datasource: url: jdbc:mysql://192.168.0.152:3306/aylson?useUnicode=true&characterEncoding=UTF-8&useSSL=false--# Test environment configuration spring: profiles: test datasource: url: jdbc:mysql://192.168.0.152:13306/aylson?useUnicode=true&characterEncoding=UTF-8&useSSL=false---# Production environment configuration spring: profiles: prod datasource: url: jdbc:mysql://192.168.0.152:23306/aylson?useUnicode=true&characterEncoding=UTF-8&useSSL=false
How to use:
Use different profiles by specifying startup parameters, such as:
Test environment: Java -jar xxx.jar spring.profiles.active=test
Production environment: java -jar xxx.jar spring.profiles.active=prod
The above article uses different configuration methods based on Spring Boot. This article is all the content I share with you. I hope it can give you a reference and I hope you can support Wulin.com more.