升级SpringBoot版本导致文件上传失败的问题

升级SpringBoot版本后遇到文件上传失败的问题,原因是新版本SpringMVC在装配时未调用特定过滤器,而老版本中该过滤器被自动装配。通过禁用引起问题的Filter解决了临时问题。深入源码发现,冈先生自定义的Servlet和过滤器交互方式在新版本中导致Request流无法正常读取。最终解决方案是在配置中显式添加过滤器。
摘要由CSDN通过智能技术生成

问题描述

因更换SpringBoot版本导致文件上传失败,版本如下:

老版本:spring-web:5.1.7.RELEASE
新版本:spring-web:5.2.4.RELEASE

其实新版本没有问题,只不过一些没有问题的代码合到一块就恰巧出现了问题

SpringMvc流程图

debug过程

我们都知道,SpringMVC是基于DispatcherServlet做统一请求处理的,那就从DispatcherServlet开始debug,下面是入口方法

protected void doService(HttpServletRequest request, HttpServletResponse response) throws Exception {
        this.logRequest(request);
        Map<String, Object> attributesSnapshot = null;
        if (WebUtils.isIncludeRequest(request)) {
            attributesSnapshot = new HashMap();
            Enumeration attrNames = request.getAttributeNames();
            while(true) {
                String attrName;
                do {
                    if (!attrNames.hasMoreElements()) {
                        break;
                    }
                    attrName = (String)attrNames.nextElement();
                } while(!this.cleanupAfterInclude && !attrName.startsWith("org.springframework.web.servlet"));

                attributesSnapshot.put(attrName, request.getAttribute(attrName));
            }
        }

        request.setAttribute(WEB_APPLICATION_CONTEXT_ATTRIBUTE, this.getWebApplicationContext());
        request.setAttribute(LOCALE_RESOLVER_ATTRIBUTE, this.localeResolver);
        request.setAttribute(THEME_RESOLVER_ATTRIBUTE, this.themeResolver);
        request.setAttribute(THEME_SOURCE_ATTRIBUTE, this.getThemeSource());
        if (this.flashMapManager != null) {
            FlashMap inputFlashMap = this.flashMapManager.retrieveAndUpdate(request, response);
            if (inputFlashMap != null) {
                request.setAttribute(INPUT_FLASH_MAP_ATTRIBUTE, Collections.unmodifiableMap(inputFlashMap));
            }

            request.setAttribute(OUTPUT_FLASH_MAP_ATTRIBUTE, new FlashMap());
            request.setAttribute(FLASH_MAP_MANAGER_ATTRIBUTE, this.flashMapManager)
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值