SpringBoot多个yml实现开发测试线上多环境
多个yml实现多环境
spring: # 环境 dev:开发环境|test:测试环境|prod:生产环境 profiles: active: dev #激活的配置文件
在激活application-dev.yml时若其中存在application.yml同名配置时后者的配置属性会被覆盖(即激活配置文件优先级高于总配置文件)
单个yml实现多环境
用---实现多文件内容的分割,application.yml中用spring.profiles.active: 实现指定的文件
spring: profiles.active: dev # 默认的profile为dev,其他环境通过指定启动参数使用不同的profile,比如: # 测试环境:java -jar spring-boot.jar --spring.profiles.active=test # 生产环境:java -jar spring-boot.jar --spring.profiles.active=prod --- # 开发环境配置 spring: profiles: dev datasource: url: jdbc:mysql://127.0.0.1:3306/demo?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=UTC username: root password: root driver-class-name: com.mysql.jdbc.Driver server: port: 8080 --- # 测试环境配置 spring: profiles: test datasource: url: jdbc:mysql://localhost:3306/demo?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=UTC username: root password: test driver-class-name: com.mysql.jdbc.Driver server: port: 88 --- # 生产环境配置 spring: profiles: prod datasource: url: jdbc:mysql://localhost:3306/demo?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=UTC username: root password: prod driver-class-name: com.mysql.jdbc.Driver
相关推荐
justlike 2020-09-02
Henryztong 2020-06-25
deadgrape 2020-06-09
abdstime 2020-06-03
jszy 2020-05-25
zzjmay 2020-05-17
HeliumLau 2020-04-21
Henryztong 2020-03-07
chichichi0 2020-02-09
woxxoole 2020-02-02
Henryztong 2020-01-30
woxxoole 2019-12-30
deyu 2019-12-18
abdstime 2019-12-10
Christsam 2019-11-19
thug 2019-11-17
hulao 2019-11-12