????????spring的配置文件默認(rèn)文件路徑是src\main\resources\application.properties,關(guān)于springBoot應(yīng)用的配置內(nèi)容都可以集中在這里,根據(jù)我們引入的不同的啟動(dòng)模塊可以 在這里定義容器的端口號(hào),數(shù)據(jù)庫(kù)連接信息等各種配置信息,今天先做一個(gè)簡(jiǎn)單的配置了解springboot的配置文件。
使用properties文件作為springBoot的配置文件(配置服務(wù)端口號(hào)),編寫好controller類
server.port=8088
啟動(dòng)springBoot后發(fā)現(xiàn)控制臺(tái)信息顯示端口不再是默認(rèn)的8080,而是修改后的8088

訪問(wèn)8088端口對(duì)應(yīng)的路徑,數(shù)據(jù)成功展示

springBoot的配置文件除了可以使用默認(rèn)的properties外,還可以使用yml(yaml)文件。yml文件的配置格式不是以單純的鍵值對(duì)來(lái)表示,而是采用了縮進(jìn)的方式來(lái)表示關(guān)系,注意:后面的空格,如下圖:

還可以在其中配置一些重要配置,使用@Value注解將其引入到類中
server:
? port: 8088
book:
? name: springCloud
? author: zhangsan
? time: 2018-8-8
在需要使用的controller中引入
@Value("${book.name}")
private Stringname;
@Value("${book.author}")
private Stringauthor;
@Value("${book.time}")
private Stringtime;
@RequestMapping("/book")?
????public String book(){
?????????????return "書名:"+name+",作者:"+author+",時(shí)間:"+time;?
? ? }? ? ? ?
訪問(wèn)對(duì)應(yīng)的路徑,數(shù)據(jù)成功展示
