Complete the code to mark the class as a Spring Boot application.
@[1] public class MyApp { public static void main(String[] args) { SpringApplication.run(MyApp.class, args); } }
The @SpringBootApplication annotation marks the main class as the entry point for Spring Boot. It enables auto-configuration and component scanning.
Complete the code to inject a service bean into the controller using annotation.
@RestController public class MyController { private final MyService service; public MyController([1] MyService service) { this.service = service; } }
The @Autowired annotation tells Spring to inject the service bean into the constructor.
Fix the error in the code by completing the annotation to define a REST endpoint.
@RestController public class HelloController { @[1]("/hello") public String sayHello() { return "Hello, World!"; } }
The @GetMapping annotation maps HTTP GET requests to the method, defining a REST endpoint.
Fill both blanks to define a service class and mark it as a Spring bean.
[1] public class UserService { public String getUser() { return "User1"; } }
The @Service annotation marks the class as a service bean for Spring to manage.
Fill all three blanks to create a REST controller with a GET endpoint that returns a greeting.
@[1] public class GreetingController { @[2]("/greet") public String greet() { return [3]; } }
The @RestController marks the class as a REST controller. @GetMapping maps GET requests to the method. The method returns a greeting string.