Spring Boot使用一個(gè)全局的配置文件application.properties或者application.yml,配置文件放在src/main/resources目錄下。
1、修改tomcat默認(rèn)端口和默認(rèn)訪問(wèn)路徑
在application.properties中添加代碼
server.contex-path=/helloboot ---------默認(rèn)訪問(wèn)路徑修改為http:l//localhost:8080/helloboot
server.port =8081-------------------端口號(hào)修改為8081
常規(guī)屬性配置
我們?cè)赼pplication.properties中定義屬性,然后再代碼中直接使用@value注入即可。
book.ruthor=羅貫中
book.name=三國(guó)
book.priyin=sanguoyanyi
類的屬性中引入注解@Value(value="${book.name}")
啟動(dòng)程序,輸入localhost:8080/hello


問(wèn)題:中文亂碼

1、查找各種資料,均是采用了設(shè)置application.properties中各種文件編譯文件的格式為UTF-8,如下
banner.charset=UTF-8server.tomcat.uri-encoding=UTF-8spring.http.encoding.charset=UTF-8spring.http.encoding.enabled=truespring.http.encoding.force=truespring.messages.encoding=UTF-8
2、對(duì)于IDEA,需要設(shè)置默認(rèn)編碼
file--->setting---->editor---->file encoding---->properties.files下的
Default encoding for properties files:UTF-8;后面的Transparent。。。。也要勾選。
之后我重新構(gòu)建了項(xiàng)目,啟動(dòng)后,中文顯示正常。

類型安全的配置
待實(shí)驗(yàn)