SpringBoot的profile
- 2019 年 10 月 4 日
- 筆記
Spring Boot – Profile不同环境配置
yml文件类型
只需要一个applcation.yml文件就能搞定,推荐此方式。
spring: profiles: active: prod --- spring: profiles: dev server: port: 19192 --- spring: profiles: test server: port: 19193 --- spring: profiles: prod include: - proddb - prodmq server: port: 19194 --- spring: profiles: proddb db: name: mysql5.7 --- spring: profiles: prodmq mq: address: 192.168.2.1
此时读取的就是prod的配置,prod包含proddb,prodmq,此时可以读取proddb,prodmq下的配置。
也可以同时激活三个配置。
spring.profiles.active: prod,proddb,prodmq
指定Profile
main方法启动方式:
// 在 Arguments里面添加 --spring.profiles.active=prod
插件启动方式:
spring-boot:run -Drun.profiles=prod
jar运行方式:
java -jar xx.jar --spring.profiles.active=prod