第一种方式:都在中 application.yml配置,用 --- 隔开,这样可以表示独立的环境,用active引用
spring:
profiles: active: test --- server: port: 8082 context-path: / spring: profiles: test datasource: url: jdbc: username: driver-class-name: com.mysql.jdbc.Driver redis: host: port: 6379 --- server: port: 8083 context-path: / spring: profiles: prod datasource: url: username: driver-class-name: com.mysql.jdbc.Driver redis: host: 192.168.1.23 database: 0 port: 6399 第二种:分文件 application-{profiles}.yml
application.yml
application-prod.yml 开发环境配置文件
application-test.yml 测试环境配置文件
在application.yml中
spring: profiles: active: test 引用测试文件
application-test.yml和application.prod.yml中分别写入自己的环境配置就可以了
server: port: 8082 context-path: / spring: datasource: url: jdbc: username: driver-class-name: