There are 4 places to put configuration files in SpringBoot project;
- file/application.yml
- file/config/application.yml
- classpath/application.yml
- classpath/application.yml
different configuration files can coexist,but different configuration files have different priority from 1 to 4
for example:
- file/application.yml config server.port: 8081
- file/config/application.yml config server.port: 8082
- classpath/application.yml config server.port: 8083
- classpath/appliation.yml config server.port: 8084
if file/application.yml exist,this application will work in 8081 prot;if delete file/application.yml,this applcaition will work with 8082 port…etc
By default, configuration files is classpath/applicaiton.yml
properties配置文件实现多环境的配置/切换
now ,create multiple configuration files in resource path:
- applicaton.propertiesconfig server.port=8080
- application-test.properties config server.port=8081
- application-dev.properties config server.port=8082
if run this application without any others conifguration file ,this application will run with 8080 port;
if you want make application-test.properties cover application.yml you can append a message in application.properties:
spring.profiles.active=test
In the same way, if you want to cover application.properties with application-dev.properties;you can append spring.profiles.active: dev to application.properties;
yml配置文件实现多环境的配置/切换
yml allow split A file to multiple areas with —- ;
for example:
application.yml:
server:port: 8080---server:port: 8081spring:profiles: test---server:port: 8082spring:profiles:dev
in this case,application will work with 8080;if you want to active test environment
server:port: 8080spring:profiles:active: test---server:port: 8081spring:profiles: test---server:port: 8082spring:profiles:dev
