我正在创建类似于https://github.com/rstoyanchev/spring-mvc-chat/的东西,我使用DeferredResult进行异步处理。我收到了错误
HTTP Status 500 - Request processing failed; nested exception is 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 "true" to servlet and filter declarations in web.xml.
我选择了java方式,因为我无法编辑我的web.xml文件。所以我在root-context.xml文件中有一个bean:
<bean id="asyncSupport" class="packagename.AsyncSupport"></bean>
这是我的AsyncSupport类
pblic class AsyncSupport implements AsyncConfigurer {
@Override
public Executor getAsyncExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(20);
executor.setMaxPoolSize(100);
executor.setQueueCapacity(200);
executor.initialize();
return executor;
}
}
似乎无法正常工作。还是同样的问题。我做得对吗?我该怎么办呢?
答案 0 :(得分:0)
在servlet配置的web.xml中,你必须设置async supoprted true
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/webmvc-config.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
<async-supported>true</async-supported>
</servlet>