我正在尝试测试DeferredResult来执行ajax长轮询,但即使在长轮询之前,使用简单数据itlef,我的ajax回调中只得到一个空响应。
@RequestMapping(value = "/xyz")
@ResponseBody
@Async
public DeferredResult<String> longPoll() {
return new DeferredResult<String>(1000L, "sample");
}
我错过了什么?此外,如果我将超时设为5000L,则不应该在5秒后响应,这也不起作用 我尝试使用Callable但仍然是空的响应。
@RequestMapping(value = "/xyz")
@ResponseBody
@Async
public Callable<String> longPoll() {
return new Callable<String>() {
@Override
public String call() throws Exception {
return "someView";
}
};
}
配置:
@Configuration
@ComponentScan("com.sample.longPoll")
@EnableAsync
@EnableWebMvc
@EnableScheduling
@Import()
public class CustomRootConfig extends WebMvcConfigurerAdapter {
@Override
public void addResourceHandlers(final ResourceHandlerRegistry registry) {
registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
}
@Override
public void addInterceptors(final InterceptorRegistry registry) {
registry.addInterceptor(new LoggingInterceptor()).excludePathPatterns("/resources/**");
super.addInterceptors(registry);
}
}
感谢。