简体   繁体   中英

Response body is empty when using DeferredResult

Response body is empty when using DeferredResult with Java Config.

Controller:

@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:

@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;
    }
}

This seems to be a bug in Jetty 9. It works with Jetty 8.

Reported an issue: https://bugs.eclipse.org/bugs/show_bug.cgi?id=408117

Does it work without using a DeferredResult? Ie

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

If that doesn't work, it may be a view related issue. If it does, then enable debug logging on or.springframework.web and look at the output for more clues. And/or add some logging of your own.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM