SpringBoot有三種文件
1.依賴配置文件:pom.xml 用來配置環境,最基本的有兩個:
1.1 父依賴
1.2 web依賴
2.配置文件兩個作用: 1.覆蓋默認配置 ,比如端口號默認爲8080,現在改成8081.
2. 添加新功能,比如加數據庫配置。
3.配置文件兩種格式: application.properties
application.yml
1.1父依賴 spring-boot-starter-parent
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.0.1.RELEASE</version>
<relativePath>../../spring-boot-dependencies</relativePath>
</parent>
1.2web依賴spring-boot-starter-dependencies
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
2.配置文件的兩個作用:1.覆蓋默認配置 ,比如端口號默認爲8080,現在改成8081.
2.添加新功能,比如加數據庫配置。
3.配置文件兩種格式:application.properties
application.yml 或者 application.yaml
4.yml 語法 簡單易懂,接近json,xml太多標籤了。
key: value value前是空格
//2種 1.普通數據
語法:key: value value前有空格
示例:name: haohao
//2.對象數據
key:
key1: value1
key2: value2
key: {key1: value1,key2: value2}
key1前面的空格個數不限定
5.注意:
路徑在: src/main/java/resources/
加載順序:在pom.xml里加載,後加載的會把前面加載的覆蓋掉。