首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >spring callable不工作

spring callable不工作
EN

Stack Overflow用户
提问于 2013-04-02 21:01:06
回答 1查看 700关注 0票数 0

我正在尝试使用spring实现长轮询,以下是示例代码

下面是我的异步方法的代码:

代码语言:javascript
复制
@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:

代码语言:javascript
复制
<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。任何帮助都将不胜感激。

EN

回答 1

Stack Overflow用户

发布于 2013-04-25 03:04:30

我的第一个怀疑是关于callable方法的参数。尝试将ExceptionHandler添加到您的控制器类,如下所示,以了解哪里出了问题:

代码语言:javascript
复制
@ExceptionHandler
@ResponseBody
public String handleException(IllegalStateException ex) {
  System.out.println("Exception --------->");
  return "Handled exception: " + ex.getMessage();
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15764801

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档