使用 spring boot 应用程序属性设置 tomcat 属性 [英] Setting a tomcat property using spring boot application properties

查看:49
本文介绍了使用 spring boot 应用程序属性设置 tomcat 属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为启动提供的 tomcat 设置 maxSwallowSize 属性.我的 application.properties 有这一行:

I want to set the maxSwallowSize property for boot supplied tomcat. My application.properties has this line:

server.context-parameters.maxSwallowSize=20971520 

由于某种原因不起作用.其他属性如 server.port 运行良好.调试 TomcatEmbeddedServletContainerFactory 中的创建我看到有一个具有此属性的 ServletContexInitializer (InitParameterConfiguringServletContextInitializer) 但它似乎没有以任何方式使用.(即使它在变量名 initializersToUse 中,具有讽刺意味的是 ;p)

Doesn't work for some reason. Other properties like server.port work well. Debugging the creation in TomcatEmbeddedServletContainerFactory I see that there is a ServletContexInitializer (InitParameterConfiguringServletContextInitializer) with this property but it doesn't seem to be used in any way. (Even though it's in a variable name initializersToUse, ironic ;p)

我不喜欢在上传超过

multipart.max-request-size=10MB
multipart.max-file-size=2MB

这是设置此属性的正确方法吗?在调试期间,我可以看到 IdentityInputFilter 的默认值为 2MB.

Is this the correct way of setting this property? During debuggin I can see that the IdentityInputFilter has the default value of 2MB.

org.springframework.boot:spring-boot-starter-web 的最新版本

newest version of org.springframework.boot:spring-boot-starter-web

推荐答案

server.context-parameters (as 文档中定义 可用于指定servlet上下文的init参数).maxSwallowSize 是连接器的一个属性.我猜那是另一回事.

server.context-parameters (as defined in the documentation can be used to specify the init parameters of the servlet context). maxSwallowSize is a property of the connector. That's a different thing I guess.

我们没有明确的属性,但您始终可以通过自己的 TomcatEmbeddedServletContainerFactory 对其进行配置.

We don't have an explicit property for that but you can always configure it via your own TomcatEmbeddedServletContainerFactory.

@Bean
public TomcatEmbeddedServletContainerFactory containerFactory() {
    return new TomcatEmbeddedServletContainerFactory() {
        protected void customizeConnector(Connector connector) {
            super.customizeConnector(connector);
            if ((connector.getProtocolHandler() instanceof AbstractHttp11Protocol) {
                (AbstractHttp11Protocol <?>) connector.getProtocolHandler()).setMaxSwallowSize(value);
            }
        }
    };

}

这篇关于使用 spring boot 应用程序属性设置 tomcat 属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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