1.如何設定值
首先我們進入ServerProperties中查看其內容:

發現其類上面有注解
@ConfigurationProperties(
prefix = “server”,
ignoreUnknownFields = true
)
prefix為前綴,前綴名為server所以我們在properties、yaml、yml檔案中可以用server.xxx的方式進行屬性配置,我們點進pom.xml檔案中的spring-boot-starter-parent:

springboot會去resources路徑下加載符合要求的檔案,從該檔案中查找配置來覆寫默認配置,檔案要求如下:

如果出現多個檔案都設定了相同的配置,最后面的檔案會覆寫前面檔案的配置,比如yaml會覆寫yml,properties會覆寫yaml,也就是說:
properties > yaml > yml
2.默認值為什么是8080
我們匯入的依賴都是jar包,默認的配置資訊存在 包名字以 *-autoconfigure.jar 形式結尾的jar包中,springboot的默認組態檔的名字為:/META-INF/spring-configuration-metadata.json,
/META-INF/additional-spring-configuration-metadata.json,這個檔案中也是默認配置,是/META-INF/spring-configuration-metadata.json 檔案中的補充配置資訊:

點進spring-configuration-metadata.json中,查看其內容,發現server.port的默認值在其中已經配置好了,默認值為8080:

轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/243979.html
標籤:其他
下一篇:OLAP與結構化資料分析
