zoukankan      html  css  js  c++  java
  • spring boot-6.profile 多环境支持

    在正式项目中一般都会区分多个环境,一般至少分为开发环境,测试生产环境,生产环境,实际可能会有更加精细的区分,针对不同的环境,项目的配置可能需要切换,spring boot 提供了很方便的环境切换方式。

    1.编写多个配置文件,命名方式为application-{profile}.yml,并在application.yml 中指定当前使用的profile。

    在项目中新建application-dev.yml 和 application-prod.yml 分别对应开发环境和生产环境,然后再application.yml中指定使用哪个profile。

    applicatiom-dev.yml

    server:
      port: 8888

    application-prod.yml

    server:
      port: 80

    在application.yml 指定使用生产环境

    spring:
      profiles:
        active: prod

    则系统以80端口启动

    如果将application.yml中指定当前profile为dev

    spring:
      profiles:
        active: dev

    则系统以8888端口启动

    2.如果不想编写多个配置文件,yml文件还支持多文档块模式,模块之间用---隔开。

    比如在application.yml中分别定义 dev 块和prod块,并指定当前启动环境

    spring:
      profiles:
        active: prod
        
        
    ---
    spring:
      profiles: dev
    server:
      port: 8081
      
      
    ---
    spring:
      profiles: prod
    server:
      port: 8082
        

    切换当前生效的文档块名称,可以从不同端口启动

    3.激活profile的方式

    (1)通过spring.profiles.active 来指定

    (2)在项目启动的时候指定

    java -jar xxxxx.jar --spring.profiles.active=dev

    (3)设置虚拟参数。

    在STS(Eclipse)的run-->run Configurations 设置运行参数

  • 相关阅读:
    js+canvas画随机4位验证码
    linux 下 查看 nginx 日志中访问前10 的 ip
    mysql greatest函数
    php 如何获取 post 传递的raw 数据
    php 监控文件变化 并上传到服务器
    php 如何统计本周 本月
    Yii2.0 GridView 的强大功能
    git 导出新修改的文件
    ubuntu16.04 下安装phpMyAdmin
    如何在ubuntu16.04 上搭建 phpstorm + xdebug 调试
  • 原文地址:https://www.cnblogs.com/li-zhi-long/p/9475816.html
Copyright © 2011-2022 走看看