zoukankan      html  css  js  c++  java
  • Spring Boot学习06多环境配置

    方式一:使用多个properties文件

    定义如下三个用于不同环境的配置文件

    1、application-dev.properties    用于开发环境

    server.port=8081

    2、application-test.properties    用于测试环境

    server.port=8082

    3、application-pro.properties    用于生产环境

    server.port=8083

    在主配置文件application.properties中,激活对应的配置文件:

    #激活application-dev.properties 配置文件
    spring.profiles.active=dev
    
    #激活application-test.properties 配置文件
    #spring.profiles.active=test
    
    #激活application-pro.properties 配置文件
    #spring.profiles.active=pro

    启动端口为:8081

    方式二:在application.yml文件中定义多个节

    server:
      port: 8080
    spring:
      profiles:
        active: test
    ---
    server:
      port: 8081
    spring:
      config:
        activate:
          on-profile: dev
    ---
    server:
      port: 8082
    spring:
      config:
        activate:
          on-profile: test
    ---
    server:
      port: 8083
    spring:
      config:
        activate:
          on-profile: pro

    启动端口为:8082

    方式三:使用虚拟机参数配置

    这样设置,启动端口是8083

    方式四:使用命令行参数

    对应的命令为:java -jar xxx.jar --spring.profiles.active=dev

    这样设置,启动端口是8081(此步设置需要先删除第三步中的虚拟机参数的设置)

  • 相关阅读:
    Codeforces Round #631 (Div. 2)
    Codeforces Round #500 (Div. 2) [based on EJOI]
    KMP+状态机
    状态机模型
    最短编辑距离
    stringstream读入-最优乘车
    多重背包
    Codeforces:B. New Year and Ascent Sequence
    查找目录下所有文件使用到的宏
    QProcess调用外部程序并带参执行
  • 原文地址:https://www.cnblogs.com/asenyang/p/15450209.html
Copyright © 2011-2022 走看看