springboot 五-配置

常用配置:更改服務(wù)端口號(hào) , 默認(rèn)的端口號(hào)是8080

yaml

yaml配置
//注意springboot版本不一樣的時(shí)候,格式會(huì)有些出入, 本次的SpringBoot ::  (v2.5.8)
server:
  port:7777
servlet:
  session:
    timeout: 30m  #測(cè)試的話 需要長(zhǎng)一些
config:
  key:YYYYY

多環(huán)境配置

1. 在配置文件中指定啟動(dòng)某個(gè)環(huán)境

創(chuàng)建一個(gè)application.yaml 并指定active的值 就會(huì)啟動(dòng)該值對(duì)應(yīng)的配置文件
運(yùn)行的時(shí)候 會(huì)自動(dòng)讀取該文件 中active對(duì)應(yīng)的值 比如test 那會(huì)將application.yaml作為啟動(dòng)時(shí)應(yīng)該使用的配置文件

spring:
  profiles:
    active: test

創(chuàng)建一個(gè)application-test.yaml

server:
  port: 8888
servlet:
  session:
    timeout: 30m  #測(cè)試的話 需要長(zhǎng)一些
config:
  key: TTTTT

創(chuàng)建一個(gè)application-dev.yaml

server:
  port: 7777
servlet:
  session:
    timeout: 30m  #測(cè)試的話 需要長(zhǎng)一些
config:
  key: YYYYY

2. pom文件添加profiles

    <profiles>
        <profile>
            <id>
                dev
            </id>
            <properties>
                <spring.profiles.active>dev</spring.profiles.active>
            </properties>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>

        </profile>
        <profile>
        <id>
            test
        </id>
        <properties>
            <spring.profiles.active>test</spring.profiles.active>
        </properties>
        </profile>
        <profile>
            <id>
                uat
            </id>
            <properties>
                <spring.profiles.active>uat</spring.profiles.active>
            </properties>
        </profile>
        
    </profiles>

3. sh腳本指定

.sh文件
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容