我正在尝试测试Spring MVC 控制器的最新异步功能,但我无法让它工作。
这是我的异步方法的代码:
@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";
}
};
}
以下是 web.xml 中的相关部分:
<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>
但是,控制台中永远不会打印“即将从 call() 返回”,我也永远不会看到这样的日志: 08:25: 17 [MvcAsync1] WebAsyncManager - ...在控制台中......
仅供参考,我使用 Spring 3.2.RC2