1.使用maven作為parent管理
maven用戶可以繼承spring-boot-starter-parent項目獲取合適的默認設置。該父項目提供一下特性:
- 默認編譯級別為Java1.6
- 源編碼格式為UTF-8
- 一個依賴管理節點,允許你省略普通依賴的標簽,繼承自Spring-boot-dependencies POM .
- 合適的資源過濾
- 合適的插件配置(exec插件,surefire,git commit ID,shade)
- 針對application.properties和application.yml的資源過濾
在項目的POM文件中添加parent配置
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.0.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
</dependencies>
如果需要生成一個可執行的jar,則添加配置
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
2.使用沒有父POM的Spring Boot
如果不喜歡繼承 spring-boot-starter-parent POM。 你可能需要使用公司標准parent, 或你可能傾向於顯式聲明所有Maven配置。如果你不使用 spring-boot-starter-parent , 通過使用一個 scope=import 的依賴, 你仍能獲取到依賴管理的好處:
<dependencyManagement>
<dependencies>
<dependency>
<!-- Import dependency management from Spring Boot -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>1.3.0.BUILD-SNAPSHOT</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
改變Java的版本
spring-boot-starter-parent 選擇相當保守的Java兼容策略。 如果你遵循我們的建議, 使用最新的Java版本, 你可以添加一個 java.version 屬性
<properties>
<java.version>1.8</java.version>
</properties>