Bird
0
0

What will happen if a class annotated with @Service is not detected by Spring's component scanning?

medium📝 component behavior Q5 of 15
Spring Boot - Spring Annotations
What will happen if a class annotated with @Service is not detected by Spring's component scanning?
AThe application will fail to start
BThe class will not be registered as a Spring bean and won't be injected
CThe class will be registered automatically anyway
DSpring will throw a compilation error
Step-by-Step Solution
Solution:
  1. Step 1: Understand component scanning

    Spring detects beans by scanning packages for stereotype annotations like @Service.
  2. Step 2: Consequence of missing scanning

    If the class is not scanned, it won't be registered as a bean and cannot be injected.
  3. Final Answer:

    The class will not be registered as a Spring bean and won't be injected -> Option B
  4. Quick Check:

    Missing scan = no bean registration [OK]
Quick Trick: Ensure package scanning includes all @Service classes [OK]
Common Mistakes:
  • Expecting compile errors
  • Assuming automatic registration
  • Thinking app startup fails

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes