1. 程式人生 > >Spring boot 使用YML檔案配置多環境

Spring boot 使用YML檔案配置多環境

兩種配置方式 1:在一個yml檔案中,2:在多個yml檔案中

1 一個yml檔案

application.yml

spring:
  profiles:
    active: dev

---
#開發環境配置
spring:
  profiles: dev

server:
  port: 1000


---
#測試環境配置
spring:
  profiles: stg

server:
  port: 1001


---
#生產環境配置
spring:
  profiles: prd

server:
  port: 1002

2 多個yml檔案

application.yml

spring:
  profiles:
    active: dev

application-dev.yml

server:
  port: 1000

application-stg.yml

server:
  port: 1001

application-prd.yml

server:
  port: 1002

廢話不多說,簡單明瞭。

相關推薦

Spring boot 使用YML檔案配置環境

兩種配置方式 1:在一個yml檔案中,2:在多個yml檔案中 1 一個yml檔案 application.yml spring: profiles: active: dev

51. spring boot屬性檔案環境配置【從零開始學Spring Boot】(

【視訊&交流平臺】 http://study.163.com/course/introduction.htm?courseId=1004329008&utm_campaign=commission&utm_source=40000000

開發框架-Spring-Spring Boot屬性檔案環境配置

原本這個章節是要介紹《log4j多環境不同日誌級別的控制的》,但是沒有這篇文章做基礎的話,學習起來還是有點難度的,所以我們先一起了解下Spring Boot屬性檔案之多環境配置,當然文章中也會提到屬性檔案的一些基本知識,然後慢慢在昇華到多環境配置。 相信很多人選擇Sp

Spring Boot yml檔案配置檔案內容

spring:   ##資料庫連線資訊   datasource:     url: jdbc:mysql://localhost:3306/test     username: root     password:

Spring Boot中實現logback環境日誌配置

cati feature gprof 配置 color app config 現在 ng- 在Spring Boot中,可以在logback.xml中的springProfile標簽中定義多個環境logback.xml: <springProfile name=

Spring Boot中實現logback環境日誌配置(日誌輸出)

  Spring Boot中實現logback多環境日誌配置 - EasonJim - 部落格園 https://www.cnblogs.com/EasonJim/p/7801549.html   Spring Boot中實現logback多環境日誌配置 方法

Spring Boot通過Profiles實現環境配置切換

1、在yml中使用pom定義的maven屬性變數 格式:@[email protected] spring: application: name: dream-web-gateway profiles: active: '@[

Spring boot中用Profile配置環境引數

一般我們在開發中,都有多套環境,比如資料庫配置,有:開發、測試、釋出三個環境。如果人工修改,一方面浪費人力,一方面也容易亂中出錯。 Spring提供了profile的功能,可以配置多套配置,在執行時指定使用那套,這樣程式碼只要一套,執行時加入不同引數就可以了。 如資料庫

Spring boot logback日誌輸出環境配置

本人專案結構如下圖:特備註意logback.xml必須要改成logback-spring.xml,參看https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-features-cus

Spring Boot 2.4 對環境配置的支援更改

在目前最新的Spring Boot 2.4版本中,對配置的載入機制做了較大的調整。相關的問題最近也被問的比較多,所以今天就花點時間,給大家講講Spring Boot 2.4的多環境配置較之前版本有哪些變化。 ## 多環境配置 **2.4版本之前** 先回顧下,2.4版本之前,我們在yaml配置檔案中,使

Spring Boot檔案檔案上傳,以及將檔案寫入響應中

單檔案上傳 配置檔案設定 @Component public class MultipartConfig { @Bean public MultipartConfigElement multipartConfigElement(){ Multipa

spring boot 註解方式配置資料來源與使用

1、首先看一下application-dev.yml 配置 spring:     datasource:         type: com.alibaba.druid.pool.Dru

Spring Boot對log4j進行環境不同日誌級別的控制.md

前言:當我們使用log4j記錄日誌時,僅通過log4j.properties對日誌級別進行控制,對於需要多環境部署的環境不是很方便,可能我們在開發環境大部分模組需要採用DEBUG級別,在測試環境可

Spring Boot + MyBatis + Pagehelper 配置資料來源

package top.cmnbgy.springbootibatismulidatasource.dataSource; import com.alibaba.druid.pool.DruidDataSource; import org.apache.ibatis.session.SqlSessionF

Spring boot 瞭解(五)(配置資料來源)

一個專案裡面訪問多個數據庫的操作,記錄如下: (學習地址:https://www.majiaxueyuan.com/front/couinfo/36) 目錄 1.application.properties檔案配置 2.建立Configure 3.建立mapper 4.執

spring-boot結合maven配置不同環境的profile

1、在spring-boot中新建配置檔案spring-boot不同環境配置檔案格式為application-{profile}.yml說明:     如果application.yml中的配置和application-{profile}.yml相沖突時,applicatio

Spring Boot整合Druid配置資料來源

 Druid是阿里開發的資料庫連線池,功能強大,號稱Java語言中最好的資料庫連線池。本文主要介紹Srping Boot下用Druid配置多個數據源,demo環境為:Spring Boot 2.1.4.RELEASE、Druid 1.1.16。 1、引入依賴 <depen

Spring Boot基礎4-配置檔案-環境配置

一. 多環境配置的好處: 1.不同環境配置可以配置不同的引數 2.便於部署,提高效率,減少出錯 二. Properties多環境配置 1. 配置啟用選項 spring.profile

SpringBoot application.yml logback.xml,環境配置,支持 java -jar --spring.profiles.active

ole att code nio nec 支持 啟動 level -s 趁今天有時間整理了一下 啟動命令為 //開發環境 java -jar app.jar --spring.profiles.active=dev--server.port=8060 //測

idea環境Spring Boot專案切換配置檔案的多種方式

1,第一種     在application.properties配置檔案裡新增一行配置。 #載入開發的配置檔案 spring.profiles.active=dev 開發配置檔案為application-dev.properties。 2,第二種 點選Edit