Bird
0
0

What is wrong with this Spring Boot bean declaration?

medium📝 Debug Q6 of 15
Spring Boot - Spring Annotations
What is wrong with this Spring Boot bean declaration?
@Component
@Scope("invalidScope")
public class TestBean { }
AThe code compiles and runs without issues
BThe bean will default to singleton scope silently
CThe scope value is invalid and causes a runtime error
DThe bean will be prototype scoped automatically
Step-by-Step Solution
Solution:
  1. Step 1: Check validity of scope value

    "invalidScope" is not a recognized Spring scope.
  2. Step 2: Understand Spring behavior on invalid scope

    Spring throws an exception at runtime for unknown scope values.
  3. Final Answer:

    The scope value is invalid and causes a runtime error -> Option C
  4. Quick Check:

    Invalid scope causes runtime error [OK]
Quick Trick: Always use valid scope names to avoid runtime errors [OK]
Common Mistakes:
  • Assuming default singleton on invalid scope
  • Expecting prototype fallback
  • Ignoring runtime exceptions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes