Bird
0
0

Why might you use @Profile annotations instead of conditional logic inside a bean's code to handle environment differences?

hard📝 Conceptual Q10 of 15
Spring Boot - Spring Annotations
Why might you use @Profile annotations instead of conditional logic inside a bean's code to handle environment differences?
ABecause @Profile automatically changes database URLs without code.
BBecause conditional logic inside beans is not supported by Spring Boot.
CBecause @Profile controls bean creation at startup, avoiding unnecessary beans and improving clarity.
DBecause @Profile allows beans to be created multiple times in different profiles.
Step-by-Step Solution
Solution:
  1. Step 1: Understand benefits of @Profile

    @Profile controls which beans are created based on environment, so only relevant beans exist at runtime.
  2. Step 2: Compare with conditional logic inside beans

    Conditional logic runs at runtime and can make code complex and less efficient.
  3. Final Answer:

    Because @Profile controls bean creation at startup, avoiding unnecessary beans and improving clarity. -> Option C
  4. Quick Check:

    @Profile manages bean lifecycle cleanly by environment [OK]
Quick Trick: Use @Profile to cleanly separate environment beans [OK]
Common Mistakes:
  • Thinking conditional logic inside beans is unsupported
  • Assuming @Profile changes config automatically
  • Believing @Profile creates multiple bean instances

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes