Spring多开发环境配置

在项目开发中,多环境的的配置可以方便在不同环境的切换,减少错误的产生

一、properties文件的多环境配置

  properties文件可以根据不同的后缀来区分不同的环境

  application.properties   //主配置文件,存放公用的配置,并且使用spring.profiles.active=dev   来指定开发环境

  application-dev.properties   开发环境配置文件

  application-test.properties   测试环境配置文件

  application-prod.properties 开发环境配置文件

二、yml文件的多环境配置

  指定开发环境

  spring:
    profiles:
      active:
      - dev

  ---    三个横杠分割配置信息

  spring:
    profiles: dev

  开发环境配置信息

  ---

  spring: 
    profiles: test

  测试环境配置信息

三、JavaConfig类多环境配置

  在配置类或方法上添加@Profile("dev")指定某个环境下进行实例化

原文地址:https://www.cnblogs.com/chenkeyu/p/8616406.html