加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – 从Gradle中的Spring Boot中排除Tomcat依赖项

发布时间:2020-12-15 02:57:21 所属栏目:Java 来源:网络整理
导读:我正在使用 Spring Boot和Jetty,我似乎无法排除Gradle构建文件中的所有Tomcat依赖项. build.gradle的相关部分: compile("org.springframework.boot:spring-boot-starter") { exclude module: "tomcat-embed-el"}compile("org.springframework.boot:spring-b
我正在使用 Spring Boot和Jetty,我似乎无法排除Gradle构建文件中的所有Tomcat依赖项.

build.gradle的相关部分:

compile("org.springframework.boot:spring-boot-starter") {
    exclude module: "tomcat-embed-el"
}
compile("org.springframework.boot:spring-boot-starter-jetty")

compile("org.springframework.boot:spring-boot-starter-web") {
    exclude module: "spring-boot-starter-tomcat"
}

然而,当我运行gradle依赖项时,tomcat的部分仍然存在,并导致WebSockets出现问题:

...
|    
+--- org.springframework.boot:spring-boot-starter-web: -> 1.4.1.RELEASE
|    +--- org.springframework.boot:spring-boot-starter:1.4.1.RELEASE (*)
|    +--- org.hibernate:hibernate-validator:5.2.4.Final
|    |    +--- javax.validation:validation-api:1.1.0.Final
|    |    +--- org.jboss.logging:jboss-logging:3.2.1.Final -> 3.3.0.Final
|    |    --- com.fasterxml:classmate:1.1.0 -> 1.3.1
|    +--- com.fasterxml.jackson.core:jackson-databind:2.8.3
|    |    +--- com.fasterxml.jackson.core:jackson-annotations:2.8.0 -> 2.8.3
|    |    --- com.fasterxml.jackson.core:jackson-core:2.8.3
|    +--- org.springframework:spring-web:4.3.3.RELEASE
|    |    +--- org.springframework:spring-aop:4.3.3.RELEASE (*)
|    |    +--- org.springframework:spring-beans:4.3.3.RELEASE (*)
|    |    +--- org.springframework:spring-context:4.3.3.RELEASE (*)
|    |    --- org.springframework:spring-core:4.3.3.RELEASE
|    +--- org.springframework:spring-webmvc:4.3.3.RELEASE
|    |    +--- org.springframework:spring-aop:4.3.3.RELEASE (*)
|    |    +--- org.springframework:spring-beans:4.3.3.RELEASE (*)
|    |    +--- org.springframework:spring-context:4.3.3.RELEASE (*)
|    |    +--- org.springframework:spring-core:4.3.3.RELEASE
|    |    +--- org.springframework:spring-expression:4.3.3.RELEASE (*)
|    |    --- org.springframework:spring-web:4.3.3.RELEASE (*)
|    --- org.springframework.boot:spring-boot-starter-tomcat:1.4.1.RELEASE
|         +--- org.apache.tomcat.embed:tomcat-embed-core:8.5.5
|         +--- org.apache.tomcat.embed:tomcat-embed-el:8.5.5
|         --- org.apache.tomcat.embed:tomcat-embed-websocket:8.5.5
|              --- org.apache.tomcat.embed:tomcat-embed-core:8.5.5
...

为什么spring-boot-starter-tomcat不能从spring-boot-starter-web中排除?

解决方法

啊哈,找到了原因.

我也有编译(“org.springframework.boot:spring-boot-starter-websocket”)依赖,这依赖于spring-boot-starter-tomcat. Gradle依赖输出误导我认为spring-boot-starter-web是Tomcat仍然存在的原因.

我不得不添加以下内容:

compile("org.springframework.boot:spring-boot-starter-websocket") {
    exclude module: "spring-boot-starter-tomcat"
}

获得的经验是,当您想要排除某些内容时,请仔细检查所有依赖项,以确保它从所有位置排除.并且可以改进gradle依赖项输出以减少误导性…

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读