Restcontroller annotation
@RestController is a Spring annotation that marks a class as a web controller whose handler return values are written directly to HTTP response bodies.
Spring Microservices in Action
A Spring annotation that marks a class as a web controller whose return values are written to the response body.
- How it is used
- Uses @RestController to expose HTTP endpoints from a Spring Boot microservice.
- How deep it goes
- Explains class-level response handling and illustrates endpoint mapping with a returned object.
- Examples
- Shows a licensing controller and a GET endpoint returning a sample License.
- What you can do after
- Apply it via Spring Boot to declare a REST controller and return a serialized object.
Read how Spring Microservices in Action explains restcontroller annotation →
Spring in Action, Sixth Edition
@RestController is a Spring annotation that marks a controller whose handler methods write response data directly to the HTTP response body by default.
- How it is used
- Creates Spring MVC REST controllers whose handler results become HTTP response data rather than view-model input.
- How deep it goes
- Explains discovery and response-body behavior, contrasts alternatives, and demonstrates endpoint mapping without covering framework internals.
- Examples
- Demonstrates a TacoController serving recent tacos at /api/tacos?recent and returning JSON, with an optional ID lookup.
- What you can do after
- Apply it via Spring MVC to build controllers that expose repository-backed data directly through REST endpoints.
Read how Spring in Action, Sixth Edition explains restcontroller annotation →
Spring Start Here, Second Edition
The @RestController annotation marks a Spring MVC controller whose actions return response data directly and are treated as REST endpoints.
- How it is used
- Avoids repeating @ResponseBody when defining Spring MVC controller actions as REST endpoints.
- How deep it goes
- Defines the annotation as a combination of @Controller and @ResponseBody, without detailing framework internals.
- Examples
- Uses a HelloController with /hello and /ciao actions returning greeting strings.
- What you can do after
- Build it from scratch by marking a controller class with @RestController instead of repeating @ResponseBody on its actions.
Read how Spring Start Here, Second Edition explains restcontroller annotation →
Also covered in
Related concepts
- JSONproduces · JSON is a language-independent text-based data-interchange format that represents structured values using objects, arrays, strings, numbers, booleans, and null.
- component scanninguses · Component scanning is a Spring mechanism that searches configured packages or classpath locations for eligible components and registers them as beans in the application context.
- controllerconfigures · A controller is a software component that receives input or requests and coordinates other components or operations to produce a response or change application state.
- serializationimplements · Serialization is the coordination of potentially concurrent operations so that specified operations occur one at a time in a defined order.
- @Controlleralternative to · The Spring @Controller annotation marks a class as a Spring-managed component for handling web requests.
- @responsebodyalternative to · @ResponseBody is a Spring annotation that directs a handler method’s return value to the HTTP response body rather than to a view resolver.
Questions about restcontroller annotation
What is restcontroller annotation?
@RestController is a Spring annotation that marks a class as a web controller whose handler return values are written directly to HTTP response bodies.
Which Manning books explain restcontroller annotation?
Spring Microservices in Action, Spring in Action, Sixth Edition and Spring Start Here, Second Edition.
What is the difference between restcontroller annotation and @Controller?
@RestController is a Spring annotation that marks a class as a web controller whose handler return values are written directly to HTTP response bodies. The Spring @Controller annotation marks a class as a Spring-managed component for handling web requests.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.


