From 26b1f44ce72705cf355ff7401620371dfa13de7c Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Wed, 12 Dec 2012 12:58:47 -0500 Subject: [PATCH] Update reference doc for async web request config Issue: SPR-9400 --- src/reference/docbook/mvc.xml | 98 ++++++++++++++++++++++++----------- 1 file changed, 69 insertions(+), 29 deletions(-) diff --git a/src/reference/docbook/mvc.xml b/src/reference/docbook/mvc.xml index 3225df34656..53150169770 100644 --- a/src/reference/docbook/mvc.xml +++ b/src/reference/docbook/mvc.xml @@ -2490,7 +2490,7 @@ deferredResult.setResult(data);
- Async Request Processing and Exception Handling + Exception Handling for Async Requests What happens if a Callable returned from a controller method raises an Exception while being executed? @@ -2560,38 +2560,78 @@ deferredResult.setResult(data);
- Async Request Configuration + Configuration for Async Request Processing - The MVC Java config and the MVC namespace provide options for - configuring async request processing. - WebMvcConfigurer has the method - configureAsyncSupport while <mvc:annotation-driven> - has an <async-support> sub-element. +
+ Servlet 3 Async Config - Those allow you to configure the default timeout value to use for - async requests, which if not set depends on the underlying Servlet - container (e.g. 10 seconds on Tomcat). You can also configure an - AsyncTaskExecutor to use for executing - Callable instances returned from - controller methods. It is highly recommended to configure this property - since by default Spring MVC uses - SimpleAsyncTaskExecutor. The MVC Java config - and the MVC namespace also allow you to register - CallableProcessingInterceptor and - DeferredResultProcessingInterceptor - instances. + To use Servlet 3 async request processing, you need to update + web.xml to version 3.0: - If you need to override the default timeout value for a - specific DeferredResult, you can do so by using - the appropriate class constructor. Similarly, for a - Callable, you can wrap it in a - WebAsyncTask and use the appropriate class - constructor to customize the timeout value. The class constructor of - WebAsyncTask also allows providing - an AsyncTaskExecutor. + <web-app xmlns="http://java.sun.com/xml/ns/javaee" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" + version="3.0"> + + ... + + <web-app> + + + The DispatcherServlet and any + Filter configuration need to have + the <async-supported>true</async-supported> sub-element. + Additionally, any Filter that also needs + to get involved in async dispatches should also be configured + to support the ASYNC dispatcher type. Note that it is safe + to enable the ASYNC dispatcher type for all filters provided with + the Spring Framework since they will not get involved in async + dispatches unless needed. + + If using Servlet 3, Java based configuration, e.g. via + WebApplicationInitializer, you'll + also need to set the "asyncSupported" flag as well as the + ASYNC dispatcher type just like with web.xml. + To simplify all this configuration, consider + extending AbstractDispatcherServletInitializer + or AbstractAnnotationConfigDispatcherServletInitializer, + which automatically set those options and make it very easy to register + Filter instances. +
+ +
+ Spring MVC Async Config + + The MVC Java config and the MVC namespace both provide options for + configuring async request processing. + WebMvcConfigurer has the method + configureAsyncSupport while <mvc:annotation-driven> + has an <async-support> sub-element. + + Those allow you to configure the default timeout value to use for + async requests, which if not set depends on the underlying Servlet + container (e.g. 10 seconds on Tomcat). You can also configure an + AsyncTaskExecutor to use for executing + Callable instances returned from + controller methods. It is highly recommended to configure this property + since by default Spring MVC uses + SimpleAsyncTaskExecutor. The MVC Java config + and the MVC namespace also allow you to register + CallableProcessingInterceptor and + DeferredResultProcessingInterceptor + instances. + + If you need to override the default timeout value for a + specific DeferredResult, you can do so by using + the appropriate class constructor. Similarly, for a + Callable, you can wrap it in a + WebAsyncTask and use the appropriate class + constructor to customize the timeout value. The class constructor of + WebAsyncTask also allows providing + an AsyncTaskExecutor. +
-
@@ -5037,7 +5077,7 @@ public class WebConfig extends WebMvcConfigurerAdapter { .rss, and .atom if the corresponding dependencies such as Jackson, JAXB2, or Rome are present on the classpath. Additional extensions may be not need - to be registered explicitly if they can be discovered via + to be registered explicitly if they can be discovered via ServletContext.getMimeType(String) or the Java Activation Framework (see javax.activation.MimetypesFileTypeMap).