@@ -2490,7 +2490,7 @@ deferredResult.setResult(data);
2490
2490
</para >
2491
2491
2492
2492
<section xml : id =" mvc-ann-async-exceptions" >
2493
- <title >Async Request Processing and Exception Handling </title >
2493
+ <title >Exception Handling for Async Requests </title >
2494
2494
2495
2495
<para >What happens if a <interfacename >Callable</interfacename > returned
2496
2496
from a controller method raises an Exception while being executed?
@@ -2560,38 +2560,78 @@ deferredResult.setResult(data);
2560
2560
</section >
2561
2561
2562
2562
<section xml : id =" mvc-ann-async-configuration" >
2563
- <title >Async Request Configuration</title >
2564
-
2565
- <para >The MVC Java config and the MVC namespace provide options for
2566
- configuring async request processing.
2567
- <interfacename >WebMvcConfigurer</interfacename > has the method
2568
- <code >configureAsyncSupport</code > while < mvc:annotation-driven>
2569
- has an < async-support> sub-element.</para >
2570
-
2571
- <para >Those allow you to configure the default timeout value to use for
2572
- async requests, which if not set depends on the underlying Servlet
2573
- container (e.g. 10 seconds on Tomcat). You can also configure an
2574
- <interfacename >AsyncTaskExecutor</interfacename > to use for executing
2575
- <interfacename >Callable</interfacename > instances returned from
2576
- controller methods. It is highly recommended to configure this property
2577
- since by default Spring MVC uses
2578
- <classname >SimpleAsyncTaskExecutor</classname >. The MVC Java config
2579
- and the MVC namespace also allow you to register
2580
- <interfacename >CallableProcessingInterceptor</interfacename > and
2581
- <interfacename >DeferredResultProcessingInterceptor</interfacename >
2582
- instances.</para >
2563
+ <title >Configuration for Async Request Processing</title >
2583
2564
2584
- <para >If you need to override the default timeout value for a
2585
- specific <classname >DeferredResult</classname >, you can do so by using
2586
- the appropriate class constructor. Similarly, for a
2587
- <interfacename >Callable</interfacename >, you can wrap it in a
2588
- <classname >WebAsyncTask</classname > and use the appropriate class
2589
- constructor to customize the timeout value. The class constructor of
2590
- <classname >WebAsyncTask</classname > also allows providing
2591
- an <interfacename >AsyncTaskExecutor</interfacename >.</para >
2565
+ <section xml : id =" mvc-ann-async-configuration-servlet3" >
2566
+ <title >Servlet 3 Async Config</title >
2592
2567
2593
- </section >
2568
+ <para >To use Servlet 3 async request processing, you need to update
2569
+ <filename >web.xml</filename > to version 3.0:</para >
2570
+
2571
+ <programlisting language =" xml" >< web-app xmlns="http://java.sun.com/xml/ns/javaee"
2572
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2573
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
2574
+ version="3.0">
2575
+
2576
+ ...
2577
+
2578
+ < web-app>
2579
+ </programlisting >
2580
+
2581
+ <para >The <classname >DispatcherServlet</classname > and any
2582
+ <interfacename >Filter</interfacename > configuration need to have
2583
+ the <code >< async-supported> true< /async-supported> </code > sub-element.
2584
+ Additionally, any <interfacename >Filter</interfacename > that also needs
2585
+ to get involved in async dispatches should also be configured
2586
+ to support the ASYNC dispatcher type. Note that it is safe
2587
+ to enable the ASYNC dispatcher type for all filters provided with
2588
+ the Spring Framework since they will not get involved in async
2589
+ dispatches unless needed.</para >
2590
+
2591
+ <para >If using Servlet 3, Java based configuration, e.g. via
2592
+ <interfacename >WebApplicationInitializer</interfacename >, you'll
2593
+ also need to set the "asyncSupported" flag as well as the
2594
+ ASYNC dispatcher type just like with <filename >web.xml</filename >.
2595
+ To simplify all this configuration, consider
2596
+ extending <classname >AbstractDispatcherServletInitializer</classname >
2597
+ or <classname >AbstractAnnotationConfigDispatcherServletInitializer</classname >,
2598
+ which automatically set those options and make it very easy to register
2599
+ <interfacename >Filter</interfacename > instances.</para >
2600
+ </section >
2601
+
2602
+ <section xml : id =" mvc-ann-async-configuration-spring-mvc" >
2603
+ <title >Spring MVC Async Config</title >
2604
+
2605
+ <para >The MVC Java config and the MVC namespace both provide options for
2606
+ configuring async request processing.
2607
+ <interfacename >WebMvcConfigurer</interfacename > has the method
2608
+ <code >configureAsyncSupport</code > while < mvc:annotation-driven>
2609
+ has an < async-support> sub-element.</para >
2610
+
2611
+ <para >Those allow you to configure the default timeout value to use for
2612
+ async requests, which if not set depends on the underlying Servlet
2613
+ container (e.g. 10 seconds on Tomcat). You can also configure an
2614
+ <interfacename >AsyncTaskExecutor</interfacename > to use for executing
2615
+ <interfacename >Callable</interfacename > instances returned from
2616
+ controller methods. It is highly recommended to configure this property
2617
+ since by default Spring MVC uses
2618
+ <classname >SimpleAsyncTaskExecutor</classname >. The MVC Java config
2619
+ and the MVC namespace also allow you to register
2620
+ <interfacename >CallableProcessingInterceptor</interfacename > and
2621
+ <interfacename >DeferredResultProcessingInterceptor</interfacename >
2622
+ instances.</para >
2623
+
2624
+ <para >If you need to override the default timeout value for a
2625
+ specific <classname >DeferredResult</classname >, you can do so by using
2626
+ the appropriate class constructor. Similarly, for a
2627
+ <interfacename >Callable</interfacename >, you can wrap it in a
2628
+ <classname >WebAsyncTask</classname > and use the appropriate class
2629
+ constructor to customize the timeout value. The class constructor of
2630
+ <classname >WebAsyncTask</classname > also allows providing
2631
+ an <interfacename >AsyncTaskExecutor</interfacename >.</para >
2632
+ </section >
2594
2633
2634
+ </section >
2595
2635
</section >
2596
2636
2597
2637
<section xml : id =" mvc-ann-tests" >
@@ -5037,7 +5077,7 @@ public class WebConfig extends WebMvcConfigurerAdapter {
5037
5077
<filename >.rss</filename >, and <filename >.atom</filename > if the
5038
5078
corresponding dependencies such as Jackson, JAXB2, or Rome
5039
5079
are present on the classpath. Additional extensions may be not need
5040
- to be registered explicitly if they can be discovered via
5080
+ to be registered explicitly if they can be discovered via
5041
5081
<classname >ServletContext.getMimeType(String)</classname > or the
5042
5082
<emphasis >Java Activation Framework</emphasis >
5043
5083
(see <classname >javax.activation.MimetypesFileTypeMap</classname >).</para >
0 commit comments