Spring Boot:使用不同的 Tomcat 版本 [英] Spring Boot: Use different Tomcat Version

查看:82
本文介绍了Spring Boot:使用不同的 Tomcat 版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Spring Boot 文档中有一个部分 使用带有 Gradle 的 Tomcat 7.x 或 8.0如一些 spring-boot-samples 所示,这对 Maven 非常有效,但不幸的是不适用于 Gradle.

In Spring Boot Documentation there is a section Use Tomcat 7.x or 8.0 with Gradle This works great with Maven as shown in some spring-boot-samples, but unfortunately not for Gradle.

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

Is there a easier solution than excluding all tomcat dependencies form tomcat-starter and add them separately with another version?

转载:如果转换示例项目 spring-boot-sample-tomcat80-ssl 进入具有以下依赖项的 Gradle 项目:

To Reproduce: If you convert the sample project spring-boot-sample-tomcat80-ssl into a Gradle project with following dependencies:

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版本:

Executing the SampleTomcatSslApplicationTests you can see the wrong Tomcat Version in Logs:

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'

推荐答案

这个问题我已经回复你了 您已创建.在您告诉我们我们的文档有误后,我花时间构建示例 完全符合 在文档中引用.

I already replied you on the issue you've created. After you've told us our documentation was wrong, I took the time to build a sample that does exactly what is referenced in the doc.

如果这对您不起作用,您必须更具体并解释文档中的错误.

If that does not work for you, you'll have to be more specific and explain what is wrong in the documentation.

这篇关于Spring Boot:使用不同的 Tomcat 版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆