最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

spring - Multipart Request configurations for StandardServletMultipartResolver not picked up - Stack Overflow

programmeradmin1浏览0评论

I had commons-fileupload before spring migration to handle multipart-form data. After spring 6.x migration I am now using StandardServletMultipartResolver by creating bean of it in servlet-context like below

<bean id="multipartResolver"
    class="org.springframework.web.multipart.support.StandardServletMultipartResolver">
</bean>

Also I have dispatcher servlet configuration in my web.xml containing <multipart-config> element as below:

<servlet>
    <servlet-name>test</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value></param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
    <multipart-config> 
        <location>test</location>
        <max-file-size>1000000</max-file-size>
        <max-request-size>1000000</max-request-size>
        <file-size-threshold>1000000</file-size-threshold>
    </multipart-config>
</servlet>

My multipart API defined inside controller is being processed successfully.

However this multipart configurations in dispatcher servlet are not picked up. Tomcat container is picking default configurations while performing request.getParts().

Below is tomcat's internal request class's code which picks default:

Context context = getContext();
MultipartConfigElement mce = getWrapper().getMultipartConfigElement();

I read that @multipartConfig annotation is for servlets and does not work for controllers. Also I don't have spring-boot in my project. Its simple spring-web application.

How to configure the filesize and other values for controllers?

发布评论

评论列表(0)

  1. 暂无评论