user3104319 user3104319 - 1 year ago 113
Java Question

Difference between spring @Controller and @RestController annotation

Difference between spring


annotation be used for both Web MVC and REST applications?

If yes, how can we differentiate if it is Web MVC or REST application.

Answer Source
  • @Controller is used to mark classes as Spring MVC Controller.
  • @RestController is a convenience annotation that does nothing more than adding the @Controller and @ResponseBody annotations (see: Javadoc)

So the following two controller definitions should do the same

public class MyController { }

public class MyRestController { }