我正在尝试使用spring实现长轮询,以下是示例代码
下面是我的异步方法的代码:
@RequestMapping(value= "failed.html" ,method = RequestMethod.POST)
protected Callable<String> callable(@ModelAttribute("user") Message user1, BindingResult bindingResult){
return new Callable<String>() {
@Override
public String call() throws Exception {
System.out.println("call--------->");
Thread.sleep(2000);
return "success";
}
};
}下面是可调用的callablecontroller servlet.xml:
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">
<bean id= "viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix"><value></value></property>
<property name="suffix" value=".jsp"></property>
</bean>
<bean id="callable" class="spring.controller.CallableController">
</bean>
然而,“call-”在控制台中从来没有打印过,而且它显示的是failed.jsp而不是success.jsp。任何帮助都将不胜感激。
发布于 2013-04-25 03:04:30
我的第一个怀疑是关于callable方法的参数。尝试将ExceptionHandler添加到您的控制器类,如下所示,以了解哪里出了问题:
@ExceptionHandler
@ResponseBody
public String handleException(IllegalStateException ex) {
System.out.println("Exception --------->");
return "Handled exception: " + ex.getMessage();
}https://stackoverflow.com/questions/15764801
复制相似问题