Skip to content

Commit 26b1f44

Browse files
committed
Update reference doc for async web request config
Issue: SPR-9400
1 parent c209b67 commit 26b1f44

File tree

1 file changed

+71
-31
lines changed

1 file changed

+71
-31
lines changed

src/reference/docbook/mvc.xml

Lines changed: 71 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2490,7 +2490,7 @@ deferredResult.setResult(data);
24902490
</para>
24912491

24922492
<section xml:id="mvc-ann-async-exceptions">
2493-
<title>Async Request Processing and Exception Handling</title>
2493+
<title>Exception Handling for Async Requests</title>
24942494

24952495
<para>What happens if a <interfacename>Callable</interfacename> returned
24962496
from a controller method raises an Exception while being executed?
@@ -2560,38 +2560,78 @@ deferredResult.setResult(data);
25602560
</section>
25612561

25622562
<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 &lt;mvc:annotation-driven&gt;
2569-
has an &lt;async-support&gt; 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>
25832564

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>
25922567

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">&lt;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"&gt;
2575+
2576+
...
2577+
2578+
&lt;web-app&gt;
2579+
</programlisting>
2580+
2581+
<para>The <classname>DispatcherServlet</classname> and any
2582+
<interfacename>Filter</interfacename> configuration need to have
2583+
the <code>&lt;async-supported&gt;true&lt;/async-supported&gt;</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 &lt;mvc:annotation-driven&gt;
2609+
has an &lt;async-support&gt; 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>
25942633

2634+
</section>
25952635
</section>
25962636

25972637
<section xml:id="mvc-ann-tests">
@@ -5037,7 +5077,7 @@ public class WebConfig extends WebMvcConfigurerAdapter {
50375077
<filename>.rss</filename>, and <filename>.atom</filename> if the
50385078
corresponding dependencies such as Jackson, JAXB2, or Rome
50395079
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
50415081
<classname>ServletContext.getMimeType(String)</classname> or the
50425082
<emphasis>Java Activation Framework</emphasis>
50435083
(see <classname>javax.activation.MimetypesFileTypeMap</classname>).</para>

0 commit comments

Comments
 (0)