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>