0

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

4

1 回答 1

0

我的第一个怀疑是关于可调用方法的参数。尝试按如下方式将 ExceptionHandler 添加到您的控制器类中,以了解发生了什么问题:

@ExceptionHandler
@ResponseBody
public String handleException(IllegalStateException ex) {
  System.out.println("Exception --------->");
  return "Handled exception: " + ex.getMessage();
}
于 2013-04-24T19:04:30.427 回答