There are 4 places to put configuration files in SpringBoot project;

  1. file/application.yml
  2. file/config/application.yml
  3. classpath/application.yml
  4. classpath/application.yml

different configuration files can coexist,but different configuration files have different priority from 1 to 4
for example:

  1. file/application.yml config server.port: 8081
  2. file/config/application.yml config server.port: 8082
  3. classpath/application.yml config server.port: 8083
  4. 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:

  1. applicaton.propertiesconfig server.port=8080
  2. application-test.properties config server.port=8081
  3. 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:

  1. server:
  2. port: 8080
  3. ---
  4. server:
  5. port: 8081
  6. spring:
  7. profiles: test
  8. ---
  9. server:
  10. port: 8082
  11. spring:
  12. profiles:dev

in this case,application will work with 8080;if you want to active test environment

  1. server:
  2. port: 8080
  3. spring:
  4. profiles:
  5. active: test
  6. ---
  7. server:
  8. port: 8081
  9. spring:
  10. profiles: test
  11. ---
  12. server:
  13. port: 8082
  14. spring:
  15. profiles:dev