Difference between @RestController and @Controller

If you are going to face Spring developer interview then this question will get shoot to you for sure.
While working with Spring you might have used these annotations.

@RestController is combination two annotations - @Controller and @ResponseBody

In Spring MVC when you are using @Controller in your class and your request mapping methods will return view. If you have used Ajax call from your view pages then you need to mark your request mapping methods you created for Ajax calls with @ResponseBody.

What is purpose of @ResponseBody ?

@ResponseBody is indicating that it will return directly HTTP response either in Json or XML.
If you put @ResponseBody at controller i.e class level then it will be applicable for all request mapping methods inside that Controller.

When you are developing REST APIs then all you need is to return Json or XML. So you need mark your controller with @Controller and @ResponseBody annotations.

Now a days most of the applications are getting developed using REST APIs.
So with Spring 4.0, it has introduced new annotation and that is @RestController.

Now instead of two annotations you can just put @RestController at your class level.