春天可赎回不起作用

时间:2013-04-02 13:01:06

标签: spring spring-mvc

我正在尝试使用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。任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

我的第一个怀疑是关于可调用方法的论据。 尝试将ExceptionHandler添加到控制器类中,如下所示,以了解哪里出错:

@ExceptionHandler
@ResponseBody
public String handleException(IllegalStateException ex) {
  System.out.println("Exception --------->");
  return "Handled exception: " + ex.getMessage();
}