Bird
0
0

Why is @SpringBootApplication typically placed on the main application class in a Spring Boot project?

easy📝 Conceptual Q2 of 15
Spring Boot - Spring Annotations
Why is @SpringBootApplication typically placed on the main application class in a Spring Boot project?
AIt automatically creates a database schema
BIt triggers component scanning from its package and sub-packages
CIt disables all auto-configuration features
DIt only marks the class as a REST controller
Step-by-Step Solution
Solution:
  1. Step 1: Understand component scanning behavior

    @SpringBootApplication includes @ComponentScan, which scans the package of the annotated class and its sub-packages for Spring components.
  2. Step 2: Reason why it is on the main class

    Placing it on the main class ensures all components in the project are detected automatically without extra configuration.
  3. Final Answer:

    It triggers component scanning from its package and sub-packages -> Option B
  4. Quick Check:

    @SpringBootApplication enables scanning from main class package [OK]
Quick Trick: Main class package is scanning root with @SpringBootApplication [OK]
Common Mistakes:
  • Thinking it creates database schema automatically
  • Believing it disables auto-configuration
  • Confusing it with @RestController

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes