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

查看:7323
本文介绍了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.

例如,如果您使用TomcatEmbeddedServletContainerFactory自定义嵌入式Tomcat容器
回调接口,
你现在应该使用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天全站免登陆