## Why is this an issue?

The Spring framework’s `@RestController` annotation is equivalent to using the `@Controller` and `@ResponseBody` annotations together. As such, it is redundant to add a `@ResponseBody` annotation when the class is already annotated with `@RestController`.

## How to fix it

Remove the `@ResponseBody` annotation from the class or method.

### Code examples

#### Noncompliant code example

    @RestController
    public class MyController {
      @ResponseBody // Noncompliant, the @RestController annotation already implies @ResponseBody
      @RequestMapping("/hello")
      public String hello() {
        return "Hello World!";
      }
    }

#### Compliant solution

    @RestController
    public class MyController {
      @RequestMapping("/hello")
      public String hello() {
        return "Hello World!";
      }
    }

#### Noncompliant code example

    @RestController
    @ResponseBody // Noncompliant, the @RestController annotation already implies @ResponseBody
    public class MyController {
      @RequestMapping("/hello")
      public String hello() {
        return "Hello World!";
      }
    }

#### Compliant solution

    @RestController
    public class MyController {
      @RequestMapping("/hello")
      public String hello() {
        return "Hello World!";
      }
    }

## Resources

### Articles & blog posts

- Spring Guides - Building a RESTful Web Service
- Baeldung - The Spring @Controller and @RestController Annotations
- Baeldung - Spring’s RequestBody and ResponseBody Annotations