设置tomcat版本时Spring Boot应用程序无法启动

问题描述 投票:0回答:1

我写在这里是因为我找不到解决我的问题的方法。 我有一个 Spring Boot 应用程序,部署在外部 tomcat 版本 10.1.6 上。 因此,为了在本地和产品上拥有相同的 tomcat 版本,我在 build.gradle 上使用 extra["tomcat.version"] = "10.1.6" 设置 Tomcat 版本。 但是当我这样做时,应用程序无法启动:

Spring Boot版本:3.3.4

***************************
APPLICATION FAILED TO START
***************************

Description:

An attempt was made to call a method that does not exist. The attempt was made from the following location:

    org.springframework.boot.autoconfigure.web.embedded.TomcatWebServerFactoryCustomizer.customizeMaxQueueCapacity(TomcatWebServerFactoryCustomizer.java:170)

The following method did not exist:

    'void org.apache.coyote.AbstractProtocol.setMaxQueueSize(int)'

The calling method's class, org.springframework.boot.autoconfigure.web.embedded.TomcatWebServerFactoryCustomizer, was loaded from the following location:

    jar:file:/Users/USER/.gradle/caches/modules-2/files-2.1/org.springframework.boot/spring-boot-autoconfigure/3.3.4/979234a0f3035fe60d5e505018789f98a7ec7ee3/spring-boot-autoconfigure-3.3.4.jar!/org/springframework/boot/autoconfigure/web/embedded/TomcatWebServerFactoryCustomizer.class

The called method's class, org.apache.coyote.AbstractProtocol, is available from the following locations:

    jar:file:/Users/USER/.gradle/caches/modules-2/files-2.1/org.apache.tomcat.embed/tomcat-embed-core/10.1.6/abacfdcc788fafbf671c6f68338bd2d5c27411e7/tomcat-embed-core-10.1.6.jar!/org/apache/coyote/AbstractProtocol.class

The called method's class hierarchy was loaded from the following locations:

    org.apache.coyote.AbstractProtocol: file:/Users/USER/.gradle/caches/modules-2/files-2.1/org.apache.tomcat.embed/tomcat-embed-core/10.1.6/abacfdcc788fafbf671c6f68338bd2d5c27411e7/tomcat-embed-core-10.1.6.jar


Action:

Correct the classpath of your application so that it contains compatible versions of the classes org.springframework.boot.autoconfigure.web.embedded.TomcatWebServerFactoryCustomizer and org.apache.coyote.AbstractProtocol


Process finished with exit code 1

为了解释我的问题,我使用 Spring Initializr 创建了一个示例项目:https://github.com/amourier63/spring-boot-set-tomcat-version

在 Build.gradle.kts 第 23 行中。如果我注释该行并启动项目,项目就会启动。但是当我取消注释时,启动失败了。

我接受任何建议...也许设置 tomcat 版本是一个坏主意。

谢谢你

spring-boot tomcat
1个回答
0
投票

Apache Tomcat v10.1.25 (

source
) 中引入了 AbstractProtocol.setMaxQueueSize() 方法,并且在配置
server.tomcat.threads.max-queue-capacity
后立即进行设置(它有默认值)。

所以简而言之,Spring Boot v3.3.4 与 Apache Tomcat v10.1.6 不兼容。

可能的解决方案是:

  • 将外部 Tomcat 更新到 v10.1.25 或更高版本(我推荐 v10.1.30,因为这是 Spring Boot v3.3.4 默认使用的版本)。

  • 或者,您可以将

    server.tomcat.threads.max-queue-capacity
    设置为非正值,因为在这种情况下
    TomcatWebServerFactoryCustomizer
    不会调用
    setMaxQueueSize()
    方法。 不过我不推荐这个。

    server.tomcat.threads.max-queue-capacity=0
    
© www.soinside.com 2019 - 2024. All rights reserved.