1、application的优先级
- /config/yaml
- classpath:yaml
- resources/config/yaml
- resources/yaml
2、第一种方式----多配置文件
application.yaml
server:
port: 8080
spring:
profiles:
active: dev
application-dev.yaml
server:
port: 8081
application-test.yaml
server:
port: 8082
运行结果:
3、第二种方式---写在一个yaml文件中
用“---”分离,注意yaml中的空格!
application.yaml
server:
port: 8080
spring:
profiles:
active: test
---
server:
port: 8081
spring:
config:
activate:
on-profile: dev
---
server:
port: 8082
spring:
config:
activate:
on-profile: test
运行结果: