spring Boot上传excel文件报错。 1、http请求 2、上传类Mu?报错-问答-阿里云开发者社区-阿里云

开发者社区> 问答> 正文
阿里云
为了无法计算的价值
打开APP
阿里云APP内打开

spring Boot上传excel文件报错。 1、http请求 2、上传类Mu?报错

2020-06-04 21:18:19 806 2

spring Boot上传excel文件报错。 1、http请求 2、上传类MultipartConfigFactory 设置? 400 报错

spring boot上传excel文件时报错(本地可以,线上报错),请大神解决...谢谢

问题见下描述

1、http请求

@RequestMapping("/batchAddPermissionVehicle")
@ResponseBody
public ResponseBase<Object> batchAddPermissionVehicle(MultipartFile file, @Param("userid") Integer userid) {
    ResponseBase<Object> res = new ResponseBase<>();
    HashMap<String, Object> data = new HashMap<>();
    int count = 0;
    try {
        String excelFileName = file.getOriginalFilename();
        boolean is03Excel = excelFileName.matches("^.+\\.(?i)(xls)$");
        //1、读取工作簿
        Workbook workbook = is03Excel ? new HSSFWorkbook(file.getInputStream()) : new XSSFWorkbook(file.getInputStream());
        //2、读取工作表
        Sheet sheet = workbook.getSheetAt(0);
        //3、读取行
        data.put("count", count);
        res.setResult("true");
        res.setData(data);
        res.setMessage("数据导入成功,本次导入" + count + "条数据");
        // workbook.close();
        file.getInputStream().close();
    } catch (Exception e) {
        data.put("count", count);
        res.setResult("false");
        res.setData(data);
        res.setMessage("数据导入失败,本次导入" + count + "条数据");
        e.printStackTrace();
    }
    return res;
}

2、上传类MultipartConfigFactory 设置

@Bean
    public MultipartConfigElement multipartConfigElement(){
        MultipartConfigFactory factory = new MultipartConfigFactory();
        //文件最大KB,MB
        factory.setMaxFileSize("10MB");
        //设置总上传数据总大小
        factory.setMaxRequestSize("15MB");
        return factory.createMultipartConfig();
    }

3、线上服务器报错:

SEVERE: Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.web.multipart.MultipartException: Could not parse multipart servlet request; nested exception is java.io.IOException: org.apache.tomcat.util.http.fileupload.FileUploadException] with root cause
java.net.SocketTimeoutException
        at org.apache.tomcat.util.net.NioBlockingSelector.read(NioBlockingSelector.java:201)
        at org.apache.tomcat.util.net.NioSelectorPool.read(NioSelectorPool.java:235)
        at org.apache.tomcat.util.net.NioSelectorPool.read(NioSelectorPool.java:216)
        at org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper.fillReadBuffer(NioEndpoint.java:1241)
        at org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper.read(NioEndpoint.java:1190)
        at org.apache.coyote.http11.Http11InputBuffer.fill(Http11InputBuffer.java:717)
        at org.apache.coyote.http11.Http11InputBuffer.access$300(Http11InputBuffer.java:40)
        at org.apache.coyote.http11.Http11InputBuffer$SocketInputBuffer.doRead(Http11InputBuffer.java:1072)
        at org.apache.coyote.http11.filters.IdentityInputFilter.doRead(IdentityInputFilter.java:140)
        at org.apache.coyote.http11.Http11InputBuffer.doRead(Http11InputBuffer.java:261)
        at org.apache.coyote.Request.doRead(Request.java:581)
        at org.apache.catalina.connector.InputBuffer.realReadBytes(InputBuffer.java:326)
        at org.apache.catalina.connector.InputBuffer.checkByteBufferEof(InputBuffer.java:642)
        at org.apache.catalina.connector.InputBuffer.read(InputBuffer.java:349)
        at org.apache.catalina.connector.CoyoteInputStream.read(CoyoteInputStream.java:183)
        at java.io.FilterInputStream.read(FilterInputStream.java:133)
        at org.apache.tomcat.util.http.fileupload.util.LimitedInputStream.read(LimitedInputStream.java:132)
        at org.apache.tomcat.util.http.fileupload.MultipartStream$ItemInputStream.makeAvailable(MultipartStream.java:977)
        at org.apache.tomcat.util.http.fileupload.MultipartStream$ItemInputStream.read(MultipartStream.java:881)
        at java.io.InputStream.read(InputStream.java:101)
        at org.apache.tomcat.util.http.fileupload.util.Streams.copy(Streams.java:98)
        at org.apache.tomcat.util.http.fileupload.util.Streams.copy(Streams.java:68)
        at org.apache.tomcat.util.http.fileupload.MultipartStream.readBodyData(MultipartStream.java:571)
        at org.apache.tomcat.util.http.fileupload.MultipartStream.discardBodyData(MultipartStream.java:595)
        at org.apache.tomcat.util.http.fileupload.MultipartStream.skipPreamble(MultipartStream.java:613)
        at org.apache.tomcat.util.http.fileupload.FileUploadBase$FileItemIteratorImpl.findNextItem(FileUploadBase.java:865)
        at org.apache.tomcat.util.http.fileupload.FileUploadBase$FileItemIteratorImpl.<init>(FileUploadBase.java:845)
        at org.apache.tomcat.util.http.fileupload.FileUploadBase.getItemIterator(FileUploadBase.java:256)
        at org.apache.tomcat.util.http.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:280)
        at org.apache.catalina.connector.Request.parseParts(Request.java:2864)
        at org.apache.catalina.connector.Request.parseParameters(Request.java:3211)
        at org.apache.catalina.connector.Request.getParameter(Request.java:1137)
        at org.apache.catalina.connector.RequestFacade.getParameter(RequestFacade.java:381)
        at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:75)
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
        at org.springframework.boot.actuate.autoconfigure.MetricsFilter.doFilterInternal(MetricsFilter.java:106)
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:478)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
        at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:803)
        at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
        at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868)
        at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1459)
        at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
        at java.lang.Thread.run(Thread.java:748)

 

 

 

 

取消 提交回答
全部回答(2)
  • 皮卡丘的二爷
    2020-06-05 11:32:27

    超时了,文件传输太慢 修改tomcat的配置文件conf/server.xml,找到下面配置信息:

               maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
               enableLookups="false" redirectPort="8443" acceptCount="100"
               connectionTimeout="20000" disableUploadTimeout="true" />
    

    将上面的参数disableUploadTimeout值改为false即可。 44看

    0 0
  • 优选2
    2020-06-05 11:35:45

    没遇到过这个错误 帮顶 看大佬怎么说

    ######

    去查看引入的包是否正确,上传的文件应该引用这个包org.springframework.web.multipart.MultipartFile

    ######回复 @北巷远人 : 感觉是上传文件超时导致的######检查过引用的包,应该是没有问题的,这个只是在线上(部署在linux服务中)会报此错误,谢谢...######

    SokcetTimeout和代理层有关,也和TOMCAT有关,上线以后,生产用户的网速就可能没那么好了,如果连接在指定时间内没有完成操作就很容易出现SocketTimeout

    ######明白,谢谢回复######

    1、检查带宽

    2、加大tomcat的连接超时时间

    ######好的,我尝试一下######

    我也遇到这个问题了,本地没问题,开发/测试环境(linux)就报错,请问大佬,这个问题是怎么解决的了?

    ######

    请问大佬,这个问题是怎么解决的了?紧急求助,在线等。。。

    ######抱歉,刚看到。这个问题我没有找到好的解决方法,应该是开发环境中的网络问题,我根据我的业务换了一种方法,如果有更好的方法,欢迎交流。
    0 0
添加回答
相关问答

1

回答

请问,后端请求未结束,spring事物为什么会提交?是单个方法执行完,事物就会自动提交嘛?

2022-07-21 10:25:22 235浏览量 回答数 1

1

回答

函数计算GB镜像中Spring Cloud Gateway接受请求的核心代码是什么?

2022-05-08 22:34:57 194浏览量 回答数 1

1

回答

Spring MVC中底层负责请求映射路由的模块是什么?

2021-11-03 12:02:25 777浏览量 回答数 1

1

回答

Spring MVC中,自定义拦截器拦截所有请求的XML配置是什么?

2021-11-02 20:57:57 409浏览量 回答数 1

0

回答

请求给为大声 spring 报错 Background retry gave up

2021-10-19 18:54:19 421浏览量 回答数 0

1

回答

spring mvc ajax请求,后台能接受,前端报错406 ?报错

2020-06-23 15:32:33 279浏览量 回答数 1

1

回答

spring mvc进入请求很慢,浏览器请求应该马上进来才对,但却要等几分钟才进?报错

2020-06-08 20:35:35 456浏览量 回答数 1

1

回答

spring模拟请求测试报错?报错

2020-06-07 22:32:21 270浏览量 回答数 1

1

回答

spring cloud Fegin请求压缩配置最小压缩的文档大小:报错

2020-06-05 23:10:42 464浏览量 回答数 1

1

回答

spring cloud版本会不会有线程数飙升的问题?

2022-11-04 17:44:15 374浏览量 回答数 1
+关注
文章
问答
问答排行榜
最热
最新
相关电子书
更多
Java Spring Boot开发实战系列课程【第15讲】:Spring Boot 2.0 API与Spring REST Docs实战
立即下载
Java Spring Boot开发实战系列课程【第7讲】:Spring Boot 2.0安全机制与MVC身份验证实战(Java面试题)
立即下载
yqdh_58c1335aa45...1510466311.pdf
立即下载