2017  Kodetalk | Feedback | Privacy Policy | Terms | About
userimage

How to create an async controller using spring framework

I am trying to create an async controller using spring. We usually using old way like

@GetMapping(value = "/test")
private ModelAndView getTest() {
	return new ModelAndView("test");
}

But as this is a old way and i am trying to do the same as async way. How to do it?

userimage

To make it async you can use below code:

@GetMapping(value = "/test")
private Callable<ModelAndView> getTest() {
	return new ModelAndView("test");
}

// or

@GetMapping(value = "/test")
private Callable<ModelAndView> getTest() {
	return () -> {
		return new ModelAndView("test");
	};
}
Answer is