Spring Boot:使用不同的 Tomcat 版本

2024-04-15

在 Spring Boot 文档中有一个部分将 Tomcat 7.x 或 8.0 与 Gradle 结合使用 https://docs.spring.io/spring-boot/docs/current/reference/html/howto-embedded-servlet-containers.html#_use_tomcat_7_x_or_8_0_with_gradle正如一些 spring-boot-samples 中所示,这对于 Maven 非常有效,但不幸的是不适用于 Gradle。

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

重现: 如果您转换示例项目spring-boot-sample-tomcat80-ssl https://github.com/spring-projects/spring-boot/tree/master/spring-boot-samples/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

SOLUTION

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

我已经就这个问题回复你了你已经创建了 https://github.com/spring-projects/spring-boot/issues/7715。在您告诉我们我们的文档有误后,我花时间建立一个样本 https://github.com/snicoll-scratches/test-gradle-tomcat80这正是做的在文档中引用 https://docs.spring.io/spring-boot/docs/current/reference/html/howto-embedded-servlet-containers.html#_use_tomcat_7_x_or_8_0_with_gradle.

如果这对您不起作用,您必须更具体并解释文档中的问题。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Spring Boot:使用不同的 Tomcat 版本 的相关文章

随机推荐

  • 静态文件application_可读用法

    我一直在尝试了解 application read 静态 url 处理程序字段的工作原理 我使用的是 SDK 版本 1 7 7 并且我已在开发环境中的应用程序上将其设置为 true 但我似乎无法实际读取该文件 app yaml url te
  • Scala 相当于 F# 中的 |> 或 Clojure 中的 ->>

    在 Scala 中 当我有这个表达式时 f1 f2 f3 p 有没有一种方法可以让我使用类似的东西 F p gt f3 gt f2 gt f1 还是 Clojure gt gt p f3 f2 f1 Scala 中没有相当于 F 的管道运算
  • 如何在一个 Tomcat + Apache 上部署多个 Grails 应用程序?

    我已经阅读了 StackOverflow 上的几个问题 并用 google 搜索了几个小时 但对于在一个 tomcat 5 5 使用 Apache 上部署多个 Grails 应用程序的问题 我找不到完整且清晰的答案 也许有人可以把我推向正确
  • C# 中的拳击发生

    我正在尝试收集 C 中发生装箱的所有情况 将值类型转换为System Object type struct S object box new S 将值类型转换为System ValueType type struct S System Va
  • 宽度为 100% 的 HTML 输入文本框溢出表格单元格

    有谁知道为什么宽度为 100 的输入元素会超出表格的单元格边框 在下面的简单示例中 输入框越过表格的单元格边框 结果非常糟糕 这已经过测试 并且在 Firefox IE7 和 Safari 上以相同的方式发生 这对你来说有意义吗 我错过了什
  • 为什么 Python 中不推荐使用 MutableString?

    为什么是可变字符串 http docs python org library userdict html UserString MutableStringPython 2 6 中已弃用的类 为什么它在 Python 3 中被删除了 The
  • 可变参数模板参数解包

    对于每个参数 我需要应用两个嵌套函数 obj apply someFilter arg arg is one argument but here should be an unpacking of args 我不知道如何为这种情况编写拆包
  • 比较两个 NSString 对象时如果“a == b”为 false

    我有一个带有可访问方法的类 该方法传回NSString当被叫时 MyClass getMyString 该类中的字符串变量实际上是在didSelectRowAtIndexPath 像这样的表的一部分 myString cell textLa
  • MySQL 将行值合并为单行

    我需要为表创建一个选择查询 该表合并 Number 列上每组的行 以获得包含所有可用但最新 按 ID 列的单行 这就是我的意思 我需要一张这样的表 ID Number Date 1 Date 2 Date 3 1 1 2011 10 01
  • VB.NET Array Contains 方法不起作用

    在 VB NET 中 我试图确定给定的字符串是否存在于字符串数组中 根据我的研究 数组有一个我可以使用的 包含 方法 因此代码如下所示 Dim fileTypesZ As String PDF TXT DOC DOCX XLS XLSX J
  • Swift 中的按钮文本下划线

    我有 UIButton 在界面生成器中 我将其标题设置为 属性 如何在 Swift 代码中使其标题带有下划线 IBOutlet weak var myBtn UIButton 我创建了一个在此按钮的 touchUpInside 事件上调用的
  • 将外部数据源与 Cucumber 功能文件集成

    我是 Cucumber 及其用于 BDD 的功能文件的新手 我想知道是否有任何方法可以直接给出外部数据文件 例如 CSV 文件 的文件路径 并获取用于创建测试脚本的参数值 您可以向功能添加带有参数的标签 data path data jso
  • Retrofit 2.0 如何解析嵌套的 JSON 对象?

    我们的团队决定使用改造2 0 http square github io retrofit 我正在对这个库进行一些初步研究 如标题所述 我想通过 Android 应用程序中的 Retrofit 2 0 解析一些嵌套的 JSON 对象 例如
  • bash + for循环+输出索引号和元素

    这是我的数组 ARRAY one two three 如何打印数组以便得到如下输出 index i element i 使用printf or for我在下面使用的循环 1 one 2 two 3 three 一些笔记供我参考 打印数组的1
  • 如何在java中读取和写入对象到文本文件?

    我有一个对象数组 我想将它们写入文本文件中 这样我以后就可以将对象读回到数组中 我该怎么做呢 使用序列化 反序列化不起作用 public static void readdata ObjectInputStream input null t
  • 如何在 Chrome 扩展中加载 Google Analytics 和 Facebook SDK?

    我正在使用 Kango 框架开发 chrome 扩展 我想同时使用 Google Analytics 和 facebook SDK 我编辑了清单文件以包含以下内容 content security policy script src sel
  • 左边补零

    我想在字符串中向左填充每个数字 必须是 8 位数字 e g asd 123 rete gt asd 00000123 rete 4444 my text gt 00004444 my text 是否可以使用正则表达式来做到这一点 尤其Reg
  • 如何使用 Twitter Bootstrap 指定多个 javascript 模式参数?

    我有一个使用 Twitter Bootstrap 创建的模式 我想用javascript打开 现在我有以下内容 但是 我还想包括背景和键盘属性 Twitter 的文档将选项显示为 my modal modal keyboard true m
  • 自定义 SAML 应用程序出现 AWS SSO“无访问错误”

    我正在尝试使用 AWS SSO 设置自定义 SAML 2 0 应用程序 但是 我从网络选项卡中收到以下错误 Status code 403 message No access type com amazonaws switchboard p
  • Spring Boot:使用不同的 Tomcat 版本

    在 Spring Boot 文档中有一个部分将 Tomcat 7 x 或 8 0 与 Gradle 结合使用 https docs spring io spring boot docs current reference html howt