Bird
0
0

Given this Spring Boot bean definition:

medium📝 component behavior Q13 of 15
Spring Boot - Advanced Patterns
Given this Spring Boot bean definition:
@Bean
@ConditionalOnProperty(name = "app.feature", havingValue = "enabled")
public Service myService() {
    return new Service();
}

What happens if the property app.feature=disabled is set in application.properties?
AThe bean <code>myService</code> is created and available
BThe bean is created but disabled
CApplication fails to start with error
DThe bean <code>myService</code> is NOT created
Step-by-Step Solution
Solution:
  1. Step 1: Understand the condition

    The bean is created only if app.feature equals "enabled".
  2. Step 2: Check the property value

    The property is set to "disabled", which does not match "enabled".
  3. Final Answer:

    The bean myService is NOT created -> Option D
  4. Quick Check:

    Property mismatch = no bean creation [OK]
Quick Trick: Bean creates only if property matches havingValue exactly [OK]
Common Mistakes:
  • Assuming bean creates regardless of property value
  • Thinking app fails to start on mismatch
  • Believing bean is created but inactive

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes