Difference between the annotations @GetMapping and @RequestMapping(method = RequestMethod.GET)

nowszy94 picture nowszy94 · Aug 22, 2016 · Viewed 128.2k times · Source

What's the difference between @GetMapping and @RequestMapping(method = RequestMethod.GET)?
I've seen in some Spring Reactive examples, that @GetMapping was used instead of @RequestMapping

Answer

dhS picture dhS · Aug 22, 2016

@GetMapping is a composed annotation that acts as a shortcut for @RequestMapping(method = RequestMethod.GET).

@GetMapping is the newer annotaion. It supports consumes

Consume options are :

consumes = "text/plain"
consumes = {"text/plain", "application/*"}

For Further details see: GetMapping Annotation

or read: request mapping variants

RequestMapping supports consumes as well

GetMapping we can apply only on method level and RequestMapping annotation we can apply on class level and as well as on method level