spring-boot-starter-parent 提供了Dependency Management 进行项目依赖的版本管理,默认的资源过滤和插件配置。
但是,当需要将其他项目作为parent 的时候,同时又希望对项目依赖版本进行统一的管理时,可以使用 dependencyManagement 来实现。
如下所示:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <!-- <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.10.RELEASE</version> <relativePath/> lookup parent from repository </parent> --> <groupId>com.study</groupId> <artifactId>SpringBootTest-1</artifactId> <version>0.0.1-SNAPSHOT</version> <name>RequestBodyTest</name> <description>Demo project for Spring Boot</description> <properties> <java.version>1.8</java.version> </properties> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-dependencies</artifactId> <version>1.5.10.RELEASE</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class SpringBootTest1Application { public static void main(String[] args) { SpringApplication.run(SpringBootTest1Application.class, args); } }
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @RestController public class HelloController { @GetMapping("/hello") public String sayHi() { return "Hello World"; } }
注意此时,
spring-boot-maven-plugin 打出来的jar包,并不包含main-class,需要配置 goal 以使打出来的Jar 可以运行。