2013-05-14 65 views
0

將DeferredResult與Java Config配合使用時,響應正文爲空。使用DeferredResult時,響應正文爲空

控制器:

@Controller 
public class HomeController { 

    @RequestMapping("/") 
    public DeferredResult<ModelAndView> home() { 
     final DeferredResult<ModelAndView> result = new DeferredResult<>(); 

     Timer timer = new Timer(); 
     timer.schedule(new TimerTask() { 
      @Override 
      public void run() { 
       result.setResult(new ModelAndView("home", Collections.singletonMap("name", "World"))); 
      } 
     }, 2); 

     return result; 
    } 
} 

配置:

@Configuration 
@ComponentScan(basePackages = "to.talk.gzip.test") 
@PropertySource(value = "classpath:/application.properties") 
@EnableWebMvc 
public class AppConfig { 

    @Bean 
    public ViewResolver mustacheViewResolver() { 
     MustacheViewResolver resolver = new MustacheViewResolver(); 
     resolver.setPrefix("views/"); 
     resolver.setSuffix(".html"); 
     return resolver; 
    } 
} 

回答

-2

是否不使用DeferredResult工作?即

@RequestMapping("/") 
public ModelAndView home() { 
    return new ModelAndView("home", Collections.singletonMap("name", "World")); 
} 

如果這不起作用,它可能是一個視圖相關的問題。如果有,請在or.springframework.web上啓用調試日誌記錄,並查看輸出以獲取更多線索。和/或添加一些你自己的日誌。

+0

將它不DeferredResult工作。看起來像最新版本的Jetty中的一個錯誤。 – 2013-05-16 14:22:37

+0

太好了,非常感謝你報告! – 2013-05-30 00:37:41