zoukankan      html  css  js  c++  java
  • 第二章:(3)Profile多环境支持

    一、Profile

      Profile是Spring对不同环境提供不同配置功能的支持,可以通过激活、指定参数等方式快速切换环境。

      我们在主配置文件编写的时候,文件名可以是 application-{profile}.properties/yml

      默认使用 application.properties 的配置

    二、声明多配置文件

      1、properties 格式

        

        指定激活的配置文件

       

      2、yml 格式:多文档块模式

        yml 支持多文档块方式

    server:
      port: 8081
    spring:
      profiles:
        active: prod   #指定激活的环境
    
    ---   #用于区分文档块
    server:
      port: 8083
    spring:
      profiles: dev
    
    
    ---
    
    server:
      port: 8084
    spring:
      profiles: prod  #指定属于哪个环境

      

    三、激活方式

      1、方式一:配置文件中指定

        可以在 application.properties 文件中指定

    spring.profiles.active=dev

        在 yml 格式中这样指定:

    spring:
      profiles:
        active: prod

      2、方式二:命令行

        在启动的时候输入参数:

    java -jar spring-boot-02-config-0.0.1-SNAPSHOT.jar --spring.profiles.active=dev;
    

          idea 中的设置:

        

      3、方式三:虚拟机参数

    -Dspring.profiles.active=dev
    

        idea中设置虚拟机参数:

        

  • 相关阅读:
    .Net Remoting使用总结
    MacOS入门
    第一部分_Mac技巧
    国内安装Homebrew
    MacOS工具
    org.springframework.beans.factory.UnsatisfiedDependencyException异常
    五天一体_企业权限管理(SSM整合)
    00_02_使用Parallels Desktop创建Windos7虚拟机
    00_01_使用Parallels Desktop创建WindosXP虚拟机
    OpenCV中几何形状识别与测量
  • 原文地址:https://www.cnblogs.com/niujifei/p/15584113.html
Copyright © 2011-2022 走看看