Bird
0
0

Consider this bean definition:

medium📝 component behavior Q5 of 15
Spring Boot - Advanced Patterns
Consider this bean definition:
@Bean
@ConditionalOnProperty(name = "app.mode", havingValue = "prod", matchIfMissing = false)
public DataSource prodDataSource() { return new DataSource(); }

If the property app.mode is not set in application.properties, what happens?
AThe bean <code>prodDataSource</code> is created
BThe bean is created with default values
CThe bean <code>prodDataSource</code> is NOT created
DAn error occurs due to missing property
Step-by-Step Solution
Solution:
  1. Step 1: Understand matchIfMissing behavior

    matchIfMissing = false means the bean is created only if the property exists and matches the value.
  2. Step 2: Analyze property absence

    Since app.mode is not set, the condition fails and the bean is not created.
  3. Final Answer:

    The bean prodDataSource is NOT created -> Option C
  4. Quick Check:

    matchIfMissing=false prevents bean creation if property missing [OK]
Quick Trick: matchIfMissing=false skips bean if property missing [OK]
Common Mistakes:
  • Assuming bean creates by default if property missing
  • Confusing matchIfMissing default value
  • Expecting error on missing property

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes