2017-02-16 96 views
3

我使用Spring引导与码头,似乎我不能排除所有Tomcat的依赖在我的摇篮构建文件。的build.gradle的不包括Tomcat的依赖性在摇篮

相关部分:

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 dependencies部分的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

回答

5

啊哈,找到了原因。

我也有compile("org.springframework.boot:spring-boot-starter-websocket")依赖性也取决于spring-boot-starter-tomcat了。摇篮依赖输出误导我以为spring-boot-starter-web就是为什么Tomcat的是仍然存在的原因。

我不得不添加以下内容:

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

获得的经验是,当你想排除的东西,仔细检查所有的依赖关系,以确保它是从所有的地方除外。和gradle这个依赖性输出可以改进,使其少误导...

6

我有同样的问题,所以就排除弹簧引导启动-tomcat的顶我也不得不排除Tomcat的embed- *罐子,我这样做通过gradle配置

configurations { 
    compile.exclude module: 'spring-boot-starter-tomcat' 
    compile.exclude group: 'org.apache.tomcat' 
}