美文网首页
profile 多环境支持

profile 多环境支持

作者: 桑鱼nicoo | 来源:发表于2020-02-20 10:33 被阅读0次

1、多Profile文件

在写主配置文件时,文件名可以是 application-{profile}.properties/yml
默认使用application.properties的配置

# application.properties
server.port=8081
spring.profiles.active=dev //  在application.properties配置文件中指定激活Profile,此时application.properties是主配置文件
# application-dev.properties
server.port=8082
# application-prod.properties
server.port=8083

2、使用yml配置多文档块方式

server:
  port: 8081
spring:
  profiles:
    active: dev // 激活profile ,如果不激活默认是8081

---
server:
  port: 8083
spring:
  profiles: dev

---

server:
  port: 8084
spring:
  profiles: prod

3、命令行方式:支持properties和yml文件

--spring.profiles.active=prod

4、命令行直接运行jar包的时,增加命令行参数

java -jar /Users/aaa/spring-test01/my-springboot-demo02/target/my-springboot-demo02-0.0.1-SNAPSHOT.jar --spring.profiles.active=dev

相关文章

网友评论

      本文标题:profile 多环境支持

      本文链接:https://www.haomeiwen.com/subject/jdfjfhtx.html