美文网首页
HttpServletResponse在异步方法中不起作用

HttpServletResponse在异步方法中不起作用

作者: 墨色尘埃 | 来源:发表于2020-04-13 17:36 被阅读0次
    @Async // TODO: 2020/4/13  使用@EnableAsync启用异步注解
    public void contextLoads(String userId, String pwd,
                             HttpServletResponse response, HttpServletRequest request) {

..........

            HSSFWorkbook workbook = ExcelUtil.createExcel(sheetName, titleList, titleEgList, depositDataList);

            //输出Excel文件
            OutputStream output = response.getOutputStream();
            response.reset();
            //中文名称要进行编码处理
            response.setHeader("Content-disposition", "attachment; filename=" + new String(fileName.getBytes("GB2312"),
                    "ISO-8859-1") + ".xls");
            response.setContentType("application/x-xls");
            workbook.write(output);
            output.close();
..........

}

报错信息

fmjs子系统ctLocation:https://fmjs.chinaccs.cn/fm/j_spring_cas_security_check;jsessionid=unHJAkpg fWr0q 3bVzeDF r.undefined?ticket=ST-597582-Glk9cGfpGdj5uv6gTgYP-cas
[ERROR] 2020-04-13 17:34:03.595 [SimpleAsyncTaskExecutor-1] c.c.i.m.b.service.ClaimService - 任务执行失败
java.lang.NullPointerException: null
    at org.apache.coyote.http11.Http11OutputBuffer.commit(Http11OutputBuffer.java:347)
    at org.apache.coyote.http11.Http11Processor.prepareResponse(Http11Processor.java:1354)
    at org.apache.coyote.AbstractProcessor.action(AbstractProcessor.java:260)
    at org.apache.coyote.Response.action(Response.java:173)
    at org.apache.coyote.http11.Http11OutputBuffer.doWrite(Http11OutputBuffer.java:219)
    at org.apache.coyote.Response.doWrite(Response.java:541)
    at org.apache.catalina.connector.OutputBuffer.realWriteBytes(OutputBuffer.java:351)
    at org.apache.catalina.connector.OutputBuffer.appendByteArray(OutputBuffer.java:785)
    at org.apache.catalina.connector.OutputBuffer.append(OutputBuffer.java:714)
    at org.apache.catalina.connector.OutputBuffer.writeBytes(OutputBuffer.java:391)
    at org.apache.catalina.connector.OutputBuffer.write(OutputBuffer.java:369)
    at org.apache.catalina.connector.CoyoteOutputStream.write(CoyoteOutputStream.java:96)
    at org.apache.poi.poifs.nio.ByteArrayBackedDataSource.copyTo(ByteArrayBackedDataSource.java:86)
    at org.apache.poi.poifs.filesystem.NPOIFSFileSystem.writeFilesystem(NPOIFSFileSystem.java:798)
    at org.apache.poi.hssf.usermodel.HSSFWorkbook.write(HSSFWorkbook.java:1415)
    at com.cicdi.invoice.modules.business.service.ClaimService.contextLoads(ClaimService.java:159)
    at com.cicdi.invoice.modules.business.service.ClaimService$$FastClassBySpringCGLIB$$4f8eadff.invoke(<generated>)
    at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:738)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
    at org.springframework.aop.interceptor.AsyncExecutionInterceptor$1.call(AsyncExecutionInterceptor.java:115)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.lang.Thread.run(Thread.java:748)

解决方法:把异步注解去掉即可

相关文章

网友评论

      本文标题:HttpServletResponse在异步方法中不起作用

      本文链接:https://www.haomeiwen.com/subject/puenmhtx.html