美文网首页
SpringBoot配置Profile多环境支持

SpringBoot配置Profile多环境支持

作者: MrJonny | 来源:发表于2018-11-07 18:23 被阅读0次

    Profile是Spring对不同环境提供不同配置功能的支持,可以通过不同需求激活指定环境配置

    1、多Profile文件定义形式
    • application-{profile}.properties或者application-{profile}.yml
      • application-dev.propertiesapplication-dev.yml
      • application-test.propertiesapplication-test.yml
      • application-prod.propertiesapplication-prod.yml
    2、多profile文档块形式
    ---
    server:
      port: 8080
    spring:
      profiles: prod
    
    ---
    server:
      port: 8081
    spring:
      profiles: test
      
    ---
    server:
      port: 8082
    spring:
      profiles: dev
    

    激活方式

    1、在yml或者properties中通过配置激活
    spring:
      profiles:
        active: dev # 激活开发环境
    
    2、命令行激活
    --spring.profiles.active=dev
    
    • 此命令式在IDEAProgram arguments输入框中设置

    • 部署到本地激活方式

      java -jar demo-0.0.1-SNAPSHOT.jar --spring.profiles.active=prod
      
    3、JVM虚拟机参数激活
    • IDEAVM Options中输入框中设置

      -Dspring.profiles.active=dev
      
    • 部署到本地激活方式

      java -jar -Dspring.profiles.active=test demo-0.0.1-SNAPSHOT.jar
      

    相关文章

      网友评论

          本文标题:SpringBoot配置Profile多环境支持

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