Async support must be enabled on a servlet and for all filters involved in async request processing

一、报错日志
java.lang.IllegalStateException: Async support must be enabled on a servlet and for all filters involved in async request processing. This is done in Java code using the Servlet API or by adding "<async-supported>true</async-supported>" to servlet and filter declarations in web.xml.

二、解决办法
 
1、修改web.xml头部信息,是因为<async-supported>true</async-supported>是web.xml 3.0的新特性,所以更改web.xml头部文件如下即可,如果是跳过:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
         version="3.0">

2、添加<async-supported>true</async-supported> 

在web.xml中对DispatcherServlet和所有filter添加 :<async-supported>true</async-supported> 

3、如果集成了shiro一定要注意在mapping中增加dispatcher项,否则会抛org.apache.shiro.UnavailableSecurityManagerException异常 

<filter-mapping>
<filter-name>shiroFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>ASYNC</dispatcher>
</filter-mapping>
4、测试代码

复制代码
@RequestMapping("callable")
@ResponseBody
public Callable<String> callable() {
    Callable<String> callable = new Callable<String>() {
        public String call() throws Exception {
            System.out.println("异步开始:" + System.currentTimeMillis());
            Thread.sleep(5000);
            System.out.println("异步结束:" + System.currentTimeMillis());
            return System.currentTimeMillis() +"";
        }
    };
    System.out.println("主线程开始:" + System.currentTimeMillis());
    return callable;
}
复制代码

 

posted @   黄进广寒  阅读(1191)  评论(0编辑  收藏  举报
编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)
历史上的今天:
2018-07-03 java12小时制的时间转换为24小时制
2018-07-03 Java数据类型和MySql数据类型对应表
2018-07-03 mybatis动态SQL中的set标签的使用
点击右上角即可分享
微信分享提示