前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >SpringBoot起步依赖

SpringBoot起步依赖

作者头像
赵哥窟
发布2021-05-24 16:01:02
9300
发布2021-05-24 16:01:02
举报
文章被收录于专栏:日常技术分享日常技术分享

搜索了很多网页也没有弄懂起步依赖是什么,看了之后总感觉懵懵懂懂的,感觉都是天下文章一大抄!下面自己总结下如果有误的地方请大神指正。

比如我们想看项目的起步依赖,可以cd到pom.xml 所在的目录下执行

代码语言:javascript
复制
mvn dependency:tree
项目依赖结构如下
代码语言:javascript
复制
[INFO] +- org.springframework.boot:spring-boot-starter:jar:2.1.4.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot:jar:2.1.4.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-autoconfigure:jar:2.1.4.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-logging:jar:2.1.4.RELEASE:compile
[INFO] |  |  +- ch.qos.logback:logback-classic:jar:1.2.3:compile
[INFO] |  |  |  \- ch.qos.logback:logback-core:jar:1.2.3:compile
[INFO] |  |  +- org.apache.logging.log4j:log4j-to-slf4j:jar:2.11.2:compile
[INFO] |  |  |  \- org.apache.logging.log4j:log4j-api:jar:2.11.2:compile
[INFO] |  |  \- org.slf4j:jul-to-slf4j:jar:1.7.26:compile
[INFO] |  +- javax.annotation:javax.annotation-api:jar:1.3.2:compile
[INFO] |  +- org.springframework:spring-core:jar:5.1.6.RELEASE:compile
[INFO] |  |  \- org.springframework:spring-jcl:jar:5.1.6.RELEASE:compile
[INFO] |  \- org.yaml:snakeyaml:jar:1.23:runtime
[INFO] +- org.springframework.boot:spring-boot-starter-web:jar:2.1.4.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-json:jar:2.1.4.RELEASE:compile
[INFO] |  |  +- com.fasterxml.jackson.core:jackson-databind:jar:2.9.8:compile
[INFO] |  |  |  \- com.fasterxml.jackson.core:jackson-core:jar:2.9.8:compile
[INFO] |  |  +- com.fasterxml.jackson.datatype:jackson-datatype-jdk8:jar:2.9.8:compile
[INFO] |  |  +- com.fasterxml.jackson.datatype:jackson-datatype-jsr310:jar:2.9.8:compile
[INFO] |  |  \- com.fasterxml.jackson.module:jackson-module-parameter-names:jar:2.9.8:compile
[INFO] |  +- org.hibernate.validator:hibernate-validator:jar:6.0.16.Final:compile
[INFO] |  |  +- javax.validation:validation-api:jar:2.0.1.Final:compile
[INFO] |  |  \- org.jboss.logging:jboss-logging:jar:3.3.2.Final:compile
[INFO] |  +- org.springframework:spring-web:jar:5.1.6.RELEASE:compile
[INFO] |  \- org.springframework:spring-webmvc:jar:5.1.6.RELEASE:compile
[INFO] +- org.springframework.boot:spring-boot-starter-undertow:jar:2.1.4.RELEASE:compile
[INFO] |  +- io.undertow:undertow-core:jar:2.0.19.Final:compile
[INFO] |  |  +- org.jboss.xnio:xnio-api:jar:3.3.8.Final:compile
[INFO] |  |  \- org.jboss.xnio:xnio-nio:jar:3.3.8.Final:runtime
[INFO] |  +- io.undertow:undertow-servlet:jar:2.0.19.Final:compile
[INFO] |  |  \- org.jboss.spec.javax.annotation:jboss-annotations-api_1.2_spec:jar:1.0.2.Final:compile
[INFO] |  +- io.undertow:undertow-websockets-jsr:jar:2.0.19.Final:compile
[INFO] |  |  \- org.jboss.spec.javax.websocket:jboss-websocket-api_1.1_spec:jar:1.1.3.Final:compile
[INFO] |  +- javax.servlet:javax.servlet-api:jar:4.0.1:compile
[INFO] |  \- org.glassfish:javax.el:jar:3.0.0:compile
[INFO] +- org.springframework.boot:spring-boot-starter-aop:jar:2.1.4.RELEASE:compile
[INFO] |  +- org.springframework:spring-aop:jar:5.1.6.RELEASE:compile
[INFO] |  \- org.aspectj:aspectjweaver:jar:1.9.2:compile
[INFO] +- org.springframework.boot:spring-boot-starter-validation:jar:2.1.4.RELEASE:compile
[INFO] |  \- org.apache.tomcat.embed:tomcat-embed-el:jar:9.0.17:compile
[INFO] +- org.springframework.security:spring-security-core:jar:4.1.5.RELEASE:compile
[INFO] |  +- aopalliance:aopalliance:jar:1.0:compile
[INFO] |  +- org.springframework:spring-beans:jar:5.1.6.RELEASE:compile
[INFO] |  +- org.springframework:spring-context:jar:5.1.6.RELEASE:compile
[INFO] |  \- org.springframework:spring-expression:jar:5.1.6.RELEASE:compile
[INFO] +- org.apache.directory.studio:org.apache.commons.codec:jar:1.8:compile
[INFO] |  \- commons-codec:commons-codec:jar:1.11:compile
[INFO] +- com.alibaba:druid:jar:1.1.8:compile
[INFO] +- com.alibaba:fastjson:jar:1.2.31:compile
[INFO] +- io.springfox:springfox-swagger2:jar:2.7.0:compile
[INFO] |  +- io.swagger:swagger-annotations:jar:1.5.13:compile
[INFO] |  +- io.swagger:swagger-models:jar:1.5.13:compile
[INFO] |  |  \- com.fasterxml.jackson.core:jackson-annotations:jar:2.9.0:compile
[INFO] |  +- io.springfox:springfox-spi:jar:2.7.0:compile
[INFO] |  |  \- io.springfox:springfox-core:jar:2.7.0:compile
[INFO] |  +- io.springfox:springfox-schema:jar:2.7.0:compile
[INFO] |  +- io.springfox:springfox-swagger-common:jar:2.7.0:compile
[INFO] |  +- io.springfox:springfox-spring-web:jar:2.7.0:compile
[INFO] |  |  \- org.reflections:reflections:jar:0.9.11:compile
[INFO] |  |     \- org.javassist:javassist:jar:3.21.0-GA:compile
[INFO] |  +- com.google.guava:guava:jar:18.0:compile
[INFO] |  +- com.fasterxml:classmate:jar:1.4.0:compile
[INFO] |  +- org.slf4j:slf4j-api:jar:1.7.26:compile
[INFO] |  +- org.springframework.plugin:spring-plugin-core:jar:1.2.0.RELEASE:compile
[INFO] |  +- org.springframework.plugin:spring-plugin-metadata:jar:1.2.0.RELEASE:compile
[INFO] |  \- org.mapstruct:mapstruct:jar:1.1.0.Final:compile
[INFO] +- io.springfox:springfox-swagger-ui:jar:2.7.0:compile
[INFO] +- com.github.penggle:kaptcha:jar:2.3.2:compile
[INFO] |  \- com.jhlabs:filters:jar:2.0.235-1:compile
[INFO] +- com.squareup.okhttp3:okhttp:jar:3.10.0:compile
[INFO] |  \- com.squareup.okio:okio:jar:1.14.0:compile
[INFO] +- com.baomidou:mybatis-plus-boot-starter:jar:3.0.5:compile
[INFO] |  +- com.baomidou:mybatis-plus:jar:3.0.5:compile
[INFO] |  |  +- com.baomidou:mybatis-plus-extension:jar:3.0.5:compile
[INFO] |  |  |  +- com.baomidou:mybatis-plus-core:jar:3.0.5:compile
[INFO] |  |  |  |  +- com.baomidou:mybatis-plus-annotation:jar:3.0.5:compile
[INFO] |  |  |  |  \- com.github.jsqlparser:jsqlparser:jar:1.2:compile
[INFO] |  |  |  +- org.mybatis:mybatis-spring:jar:1.3.2:compile
[INFO] |  |  |  \- org.mybatis:mybatis:jar:3.4.6:compile
[INFO] |  |  \- com.baomidou:mybatis-plus-generator:jar:3.0.5:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-jdbc:jar:2.1.4.RELEASE:compile
[INFO] |  |  +- com.zaxxer:HikariCP:jar:3.2.0:compile
[INFO] |  |  \- org.springframework:spring-jdbc:jar:5.1.6.RELEASE:compile
[INFO] |  |     \- org.springframework:spring-tx:jar:5.1.6.RELEASE:compile
[INFO] |  \- org.springframework.boot:spring-boot-configuration-processor:jar:2.1.4.RELEASE:optional
[INFO] +- org.apache.velocity:velocity:jar:1.7:compile
[INFO] |  +- commons-collections:commons-collections:jar:3.2.1:compile
[INFO] |  \- commons-lang:commons-lang:jar:2.4:compile
[INFO] +- mysql:mysql-connector-java:jar:8.0.15:runtime
[INFO] +- org.apache.commons:commons-pool2:jar:2.6.1:compile
[INFO] +- org.projectlombok:lombok:jar:1.18.6:compile (optional) 
[INFO] +- org.springframework.boot:spring-boot-starter-test:jar:2.1.4.RELEASE:test
[INFO] |  +- org.springframework.boot:spring-boot-test:jar:2.1.4.RELEASE:test
[INFO] |  +- org.springframework.boot:spring-boot-test-autoconfigure:jar:2.1.4.RELEASE:test
[INFO] |  +- com.jayway.jsonpath:json-path:jar:2.4.0:test
[INFO] |  |  \- net.minidev:json-smart:jar:2.3:test
[INFO] |  |     \- net.minidev:accessors-smart:jar:1.2:test
[INFO] |  |        \- org.ow2.asm:asm:jar:5.0.4:test
[INFO] |  +- junit:junit:jar:4.12:test
[INFO] |  +- org.assertj:assertj-core:jar:3.11.1:test
[INFO] |  +- org.mockito:mockito-core:jar:2.23.4:test
[INFO] |  |  +- net.bytebuddy:byte-buddy:jar:1.9.12:compile
[INFO] |  |  +- net.bytebuddy:byte-buddy-agent:jar:1.9.12:test
[INFO] |  |  \- org.objenesis:objenesis:jar:2.6:test
[INFO] |  +- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO] |  +- org.hamcrest:hamcrest-library:jar:1.3:test
[INFO] |  +- org.skyscreamer:jsonassert:jar:1.5.0:test
[INFO] |  |  \- com.vaadin.external.google:android-json:jar:0.0.20131108.vaadin1:test
[INFO] |  +- org.springframework:spring-test:jar:5.1.6.RELEASE:test
[INFO] |  \- org.xmlunit:xmlunit-core:jar:2.6.2:test
[INFO] +- org.apache.poi:poi-ooxml:jar:4.1.0:compile
[INFO] |  +- org.apache.poi:poi:jar:4.1.0:compile
[INFO] |  |  +- org.apache.commons:commons-collections4:jar:4.3:compile
[INFO] |  |  \- org.apache.commons:commons-math3:jar:3.6.1:compile
[INFO] |  +- org.apache.poi:poi-ooxml-schemas:jar:4.1.0:compile
[INFO] |  |  \- org.apache.xmlbeans:xmlbeans:jar:3.1.0:compile
[INFO] |  +- org.apache.commons:commons-compress:jar:1.18:compile
[INFO] |  \- com.github.virtuald:curvesapi:jar:1.06:compile
[INFO] +- xerces:xercesImpl:jar:2.12.0:compile
[INFO] |  \- xml-apis:xml-apis:jar:1.4.01:compile
[INFO] +- cn.hutool:hutool-all:jar:4.5.7:compile
[INFO] +- com.belerweb:pinyin4j:jar:2.5.1:compile
[INFO] +- org.bouncycastle:bcprov-jdk15on:jar:1.60:compile
[INFO] \- javax.mail:mail:jar:1.4.7:compile
[INFO]    \- javax.activation:activation:jar:1.1:compile
用法

在特殊的情况下覆盖或排除这些传递依赖: 比如Web起步依赖,它传递依赖了 Jackson JSON库,如果应用程序里不需要这个库进行如下操作就可以了。

代码语言:javascript
复制
<!--添加web起步依赖-->
<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-web</artifactId>
  <!--排除不需要的传递依赖-->
  <exclusions>
    <exclusion>
    <groupId>com.fasterxml.jackson.core</groupId>
    </exclusion>
  </exclusions>
</dependency>
什么是起步依赖

Spring Boot通过起步依赖为项目的依赖管理提供帮助。如果应用程序需要Web功能,可以直接向项目中添加spring-boot-starter-web起步依赖。如果需要安全功能,就加入security起步依赖就可以。我们不需要关心这些依赖需要什么库以及库的版本号。

起步依赖就是特殊的Maven依赖,利用了传递依赖解析,把常用库聚合在一起,组成几个为特定功能而定制的依赖。Spring Boot通过起步依赖:直接引入相关起步依赖就行,我们不需要考虑支持某种功能需要什么库, 减少了依赖数量,而且不需要考虑这些库的那些版本。如果我们需要什么功能,就往项目中加入该功能的起步依赖就好了。

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 项目依赖结构如下
  • 用法
    • 什么是起步依赖
    领券
    问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档