Complete the code to declare a Spring component class.
@[1] public class MyComponent { }
The @Component annotation marks a class as a Spring component for dependency injection.
Complete the code to declare a service class in Spring Boot.
@[1] public class UserService { }
The @Service annotation marks a class as a service layer component, typically holding business logic.
Fix the error in the annotation to mark a data access class.
@[1] public class UserRepository { }
The @Repository annotation marks a class as a data access component, handling database operations.
Complete the code to declare a Spring MVC controller class with a request mapping.
@[1] @RequestMapping("/users") public class UserController { @GetMapping public String listUsers() { return "userList"; } }
The @Controller annotation marks a class as a Spring MVC controller to handle web requests.
Fill all three blanks to complete a Spring Boot REST controller with service injection.
@[1] public class ProductController { private final ProductService productService; public ProductController([2] productService) { this.productService = productService; } @GetMapping("/products") public List<Product> getAllProducts() { return productService.[3](); } }
@RestController marks the class as a REST controller.
The constructor parameter must be the service type ProductService.
The method called on the service to get products is getProducts().