spring-boot-starter-parent、spring-boot-starter-web、spring-boot-starter-test的功能

继承 parent 父模块,spring-boot-starter-parent 模块中包含了自动配置、日志和YAML(参考:https://my.oschina.net/u/3235888/blog/887854) ,使构建spring项目变得简单。 <!--&nbsp...

继承 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>
在spring-boot中,模块的依赖都是以starter的方式进行,以 spring-boot-starter-方式命名,指明了具体的模块。spring-boot生态中提供了丰富的starter供开发者使用(参考:https://my.oschina.net/u/3235888/blog/887854)
这种模块化的依赖,简化了大量的依赖配置。使用starter的依赖方式,可以把相应需要依赖的包一起依赖到项目中,而不像传统的Spring 需要各自依赖包。
如在spring-boot中web模块,在传统的Spring配置中需要依赖 org.springframework spring-web 等web服务的包,在spring-boot中,只需要依赖spring-boot-starter-web 就能把相应的包一并依赖进来,极大的简化了配置。


  • 发表于 2018-09-19 10:12
  • 阅读 ( 4059 )
  • 分类:J2EE框架

条评论

请先 登录 后评论
不写代码的码农
三叔

422 篇文章

作家榜 »

  1. 小编 文章
返回顶部
部分文章转自于网络,若有侵权请联系我们删除