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

前端之家收集整理的这篇文章主要介绍了java – 从Gradle中的Spring Boot中排除Tomcat依赖项前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用 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依赖项输出以减少误导性…

猜你在找的Java相关文章