Bird
0
0

Given this code snippet:

medium📝 component behavior Q5 of 15
Spring Boot - Spring Annotations
Given this code snippet:
@RestController
public class MyController {
  @GetMapping("/hello")
  public String sayHello() { return "Hi"; }
}

What annotation enables Spring Boot to detect this controller automatically?
A@EnableAutoConfiguration
B@Controller
C@SpringBootApplication
D@ComponentScan
Step-by-Step Solution
Solution:
  1. Step 1: Identify how Spring Boot detects components

    @SpringBootApplication includes @ComponentScan which detects @RestController classes.
  2. Step 2: Check other annotations

    @EnableAutoConfiguration configures beans but does not scan; @ComponentScan is included inside @SpringBootApplication; @Controller is a base annotation but @RestController is used here.
  3. Final Answer:

    @SpringBootApplication -> Option C
  4. Quick Check:

    Controller detection via @SpringBootApplication [OK]
Quick Trick: Use @SpringBootApplication to enable scanning of controllers [OK]
Common Mistakes:
  • Choosing @EnableAutoConfiguration alone
  • Confusing @Controller with scanning mechanism
  • Thinking @ComponentScan alone is enough without main annotation

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes