小编典典

Spring Boot:使用不同的Tomcat版本

spring-boot

在Spring Boot文档中,有一节将Tomcat 7.x或8.0与Gradle 一起使用。如某些spring-boot-
samples中所示,这与Maven 结合使用非常好,但不幸的是,不适用于Gradle。

有没有比从tomcat-starter中排除所有tomcat依赖项并将它们单独添加到另一个版本更简单的解决方案?

重现:如果将示例项目spring-boot-sample-tomcat80-ssl转换为具有以下依赖项的Gradle项目:

dependencies {
    compile("org.springframework.boot:spring-boot-starter:1.4.2.RELEASE")
    compile("org.springframework.boot:spring-boot-starter-tomcat:1.4.2.RELEASE")
    compile("org.springframework:spring-webmvc:4.3.4.RELEASE")
    compile("org.apache.httpcomponents:httpclient:4.5.2")
    compile("org.apache.tomcat:tomcat-juli:8.0.36")
    compile("org.yaml:snakeyaml:1.17")
    testCompile 'org.springframework.boot:spring-boot-starter-test:1.4.2.RELEASE'
}

来自的输出gradlew dependencies如下所示:

compile - Dependencies for source set 'main'.
+--- org.springframework.boot:spring-boot-starter:1.4.2.RELEASE
|    +--- org.springframework.boot:spring-boot:1.4.2.RELEASE
|    |    +--- org.springframework:spring-core:4.3.4.RELEASE
|    |    |    \--- commons-logging:commons-logging:1.2
|    |    \--- org.springframework:spring-context:4.3.4.RELEASE
|    |         +--- org.springframework:spring-aop:4.3.4.RELEASE
|    |         |    +--- org.springframework:spring-beans:4.3.4.RELEASE
|    |         |    |    \--- org.springframework:spring-core:4.3.4.RELEASE (*)
|    |         |    \--- org.springframework:spring-core:4.3.4.RELEASE (*)
|    |         +--- org.springframework:spring-beans:4.3.4.RELEASE (*)
|    |         +--- org.springframework:spring-core:4.3.4.RELEASE (*)
|    |         \--- org.springframework:spring-expression:4.3.4.RELEASE
|    |              \--- org.springframework:spring-core:4.3.4.RELEASE (*)
|    +--- org.springframework.boot:spring-boot-autoconfigure:1.4.2.RELEASE
|    |    \--- org.springframework.boot:spring-boot:1.4.2.RELEASE (*)
|    +--- org.springframework.boot:spring-boot-starter-logging:1.4.2.RELEASE
|    |    +--- ch.qos.logback:logback-classic:1.1.7
|    |    |    +--- ch.qos.logback:logback-core:1.1.7
|    |    |    \--- org.slf4j:slf4j-api:1.7.20 -> 1.7.21
|    |    +--- org.slf4j:jcl-over-slf4j:1.7.21
|    |    |    \--- org.slf4j:slf4j-api:1.7.21
|    |    +--- org.slf4j:jul-to-slf4j:1.7.21
|    |    |    \--- org.slf4j:slf4j-api:1.7.21
|    |    \--- org.slf4j:log4j-over-slf4j:1.7.21
|    |         \--- org.slf4j:slf4j-api:1.7.21
|    +--- org.springframework:spring-core:4.3.4.RELEASE (*)
|    \--- org.yaml:snakeyaml:1.17
+--- org.springframework.boot:spring-boot-starter-tomcat:1.4.2.RELEASE
|    +--- org.apache.tomcat.embed:tomcat-embed-core:8.5.6
|    +--- org.apache.tomcat.embed:tomcat-embed-el:8.5.6
|    \--- org.apache.tomcat.embed:tomcat-embed-websocket:8.5.6
|         \--- org.apache.tomcat.embed:tomcat-embed-core:8.5.6
+--- org.springframework:spring-webmvc:4.3.4.RELEASE
|    +--- org.springframework:spring-aop:4.3.4.RELEASE (*)
|    +--- org.springframework:spring-beans:4.3.4.RELEASE (*)
|    +--- org.springframework:spring-context:4.3.4.RELEASE (*)
|    +--- org.springframework:spring-core:4.3.4.RELEASE (*)
|    +--- org.springframework:spring-expression:4.3.4.RELEASE (*)
|    \--- org.springframework:spring-web:4.3.4.RELEASE
|         +--- org.springframework:spring-aop:4.3.4.RELEASE (*)
|         +--- org.springframework:spring-beans:4.3.4.RELEASE (*)
|         +--- org.springframework:spring-context:4.3.4.RELEASE (*)
|         \--- org.springframework:spring-core:4.3.4.RELEASE (*)
+--- org.apache.httpcomponents:httpclient:4.5.2
|    +--- org.apache.httpcomponents:httpcore:4.4.4
|    +--- commons-logging:commons-logging:1.2
|    \--- commons-codec:commons-codec:1.9
+--- org.apache.tomcat:tomcat-juli:8.0.36
\--- org.yaml:snakeyaml:1.17

执行,SampleTomcatSslApplicationTests您会在日志中看到错误的Tomcat版本:

2016-12-21 10:20:36.713  INFO 11368 --- [           main] o.apache.catalina.core.StandardService   : Starting service Tomcat
2016-12-21 10:20:36.714  INFO 11368 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.6

  • 使用spring boot gradle插件->魔术来了
  • ext['tomcat.version'] = '8.0.36'在构建脚本中设置

阅读 282

收藏
2020-05-30

共1个答案

小编典典

对于您所创建的问题,我已经回答了您。在您告诉我们我们的文档有误之后,我花了一些时间来构建一个示例该示例完全执行doc中引用的内容

如果那对您不起作用,则您必须更加具体,并说明文档中有什么问题。

2020-05-30