Announcement Announcement Module
Collapse
No announcement yet.
Issue with making a controller method asynchronous with Spring 3.2.RC2... Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Issue with making a controller method asynchronous with Spring 3.2.RC2...

    Hello,

    I am trying to test the latest asynchronous feature of Spring MVC controllers but I have not been able to get it to work.

    Here is the code for my async method:
    Code:
    @RequestMapping(value = "/hello")
    	public Callable<String> async(final Model model) {
    		System.out.println("entered async controller method");
    		return new Callable<String>() {
    			public String call() throws Exception {
    				Thread.sleep(2000L);
    				model.addAttribute("message", "asyncRequest dealt with");
    				System.out.println("about to return from call()");
    				return "hello";
    			}
    		};
    }
    Here is the relevant portion from web.xml:
    Code:
    	<servlet>
    		<servlet-name>SpringMVC</servlet-name>
    		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    		<init-param>
    			<param-name>contextConfigLocation</param-name>
    			<param-value>/WEB-INF/spring/webmvc-config.xml</param-value>
    		</init-param>
    		<load-on-startup>1</load-on-startup>
    		<async-supported>true</async-supported>
    	</servlet>
    However "about to return from call()" is never printed in the console and I never get to see such logs as this: 08:25:17 [MvcAsync1] WebAsyncManager - ...
    in the console...

    FYI, I use Spring 3.2.RC2

    Can anyone please help?

    Regards,

    Julien.

  • #2
    I finally found why my sample was not working: one has to add the following to the web-mvc configuration file:

    Code:
    <mvc:annotation-driven>
    	<mvc:async-support default-timeout="3000"/>
    </mvc:annotation-driven>
    Regards,

    Julien.

    Comment

    Working...
    X