@Controller
→ @RestController
I had the same issue and I noticed that my controller was also annotated with @Controller
. Replacing it with @RestController
solved the issue. Here is the explanation from Spring Web MVC:
@RestController is a composed annotation that is itself meta-annotated
with @Controller and @ResponseBody indicating a controller whose every
method inherits the type-level @ResponseBody annotation and therefore
writes directly to the response body vs view resolution and rendering
with an HTML template.