我想測試Spring MVC控制器的最新異步功能,但我一直無法使其工作。使用與Spring 3.2異步的控制器方法問題.RC2
這裏是我的異步方法的代碼:
@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>
然而「即將從調用返回()」是從來沒有打印在控制檯,我永遠不會看到這樣的日誌:08:25:17 [MvcAsync1] WebAsyncManager - ... 在控制檯...
僅供參考,我使用Spring 3.2.RC2