← All tutorials

GoCareerGo Tutorials

Spring Boot Tutorial

Auto-configuration, REST APIs, JPA, AOP, caching, microservices and Spring Cloud.

Spring Boot Annotations Overview

A handful of annotations account for most of what you'll write in a typical Spring Boot application.

  • @SpringBootApplication — marks the main class, enables auto-configuration & component scan
  • @RestController / @Controller — marks a class as a web request handler
  • @Service, @Repository, @Component — stereotypes for the IoC container
  • @Autowired — injects a dependency from the container
  • @RequestMapping / @GetMapping / @PostMapping — maps HTTP routes to methods
  • @Value — injects a value from application.properties
@RestController
@RequestMapping("/api/users")
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("/{id}")
    public User getUser(@PathVariable Long id) {
        return userService.findById(id);
    }
}