继承 parent 父模块,spring-boot-starter-parent 模块中包含了自动配置、日志和YAML(参考:https://my.oschina.net/u/3235888/blog/887854) ,使构建spring项目变得简单。
<!-- 继承 spring boot 父包--><parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.4.RELEASE</version> <relativePath/> <!-- lookup parent from repository --></parent>
pom.xml中依赖 spring-boot-starter-web 模块,包括了Tomcat和spring-webmvc(参考:https://my.oschina.net/u/3235888/blog/887854) ,不需要指定version 版本,因为父模块中已经有默认配置,如果需要指定版本可添加。
<!-- 构建web项目模块 包括了Tomcat和spring-webmvc --><!-- spring-boot-starter-web 默认依赖了tomcat的starter 所以使得项目可以直接运行而不需要部署到tomcat中--><dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId></dependency>
pom.xml中依赖 spring-boot-starter-test 测试模块,包括JUnit、Hamcrest、Mockito
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope></dependency>