Spring Boot 2 中缺少 TomcatEmbeddedServletContainerFactory [英] TomcatEmbeddedServletContainerFactory is missing in Spring Boot 2

查看:56
本文介绍了Spring Boot 2 中缺少 TomcatEmbeddedServletContainerFactory的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 Spring Boot 应用程序版本 1.5.x,它使用 org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory,我正在尝试将它迁移到 Spring Boot 2,但是应用程序无法编译,尽管它依赖于 org.springframework.boot:spring-boot-starter-tomcat.编译器发出以下错误:

I have Spring Boot application version 1.5.x, which uses org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory, I'm trying to migrate it to Spring Boot 2, but the app does not compile, although a have a dependency to org.springframework.boot:spring-boot-starter-tomcat. The compiler issues the error below:

error: package org.springframework.boot.context.embedded.tomcat

推荐答案

该类已被移除并替换为 org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory更多信息请查看:Spring-Boot-2.0-Migration-Guide,其中说:

The class has been removed and replaced by org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory For more info check: Spring-Boot-2.0-Migration-Guide, which says:

为了支持响应式用例,嵌入式容器包结构已进行了相当广泛的重构.EmbeddedServletContainer 已重命名为 WebServer,并且org.springframework.boot.context.embedded 包已重新定位到 org.springframework.boot.web.server.相应地,EmbeddedServletContainerCustomizer 已重命名为WebServerFactoryCustomizer.

In order to support reactive use cases, the embedded containers package structure has been refactored quite extensively. EmbeddedServletContainer has been renamed to WebServer and the org.springframework.boot.context.embedded package has been relocated to org.springframework.boot.web.server. Correspondingly, EmbeddedServletContainerCustomizer has been renamed to WebServerFactoryCustomizer.

例如,如果您正在自定义嵌入式 Tomcat 容器使用 TomcatEmbeddedServletContainerFactory 回调接口,你现在应该使用 TomcatServletWebServerFactory ,如果你正在使用一个 EmbeddedServletContainerCustomizer bean,你现在应该使用一个WebServerFactoryCustomizer bean.

For example, if you were customizing the embedded Tomcat container using the TomcatEmbeddedServletContainerFactory callback interface, you should now use TomcatServletWebServerFactory and if you were using an EmbeddedServletContainerCustomizer bean, you should now use a WebServerFactoryCustomizer bean.

我的问题是我需要发送更大的请求,然后允许默认大小:

I had the problem that I needed to sent bigger request, then the default size allowed:

@Bean
    public TomcatServletWebServerFactory containerFactory() {
        return new TomcatServletWebServerFactory() {
            protected void customizeConnector(Connector connector) {
                int maxSize = 50000000;
                super.customizeConnector(connector);
                connector.setMaxPostSize(maxSize);
                connector.setMaxSavePostSize(maxSize);
                if (connector.getProtocolHandler() instanceof AbstractHttp11Protocol) {

                    ((AbstractHttp11Protocol <?>) connector.getProtocolHandler()).setMaxSwallowSize(maxSize);
                    logger.info("Set MaxSwallowSize "+ maxSize);
                }
            }
        };

    }

这篇关于Spring Boot 2 中缺少 TomcatEmbeddedServletContainerFactory的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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