Bird
0
0

You want your custom auto-configuration to activate only if a property my.feature.enabled is true. Which annotation should you add to your configuration class?

hard📝 Application Q8 of 15
Spring Boot - Advanced Patterns
You want your custom auto-configuration to activate only if a property my.feature.enabled is true. Which annotation should you add to your configuration class?
A@ConditionalOnProperty(name = "my.feature.enabled", havingValue = "true")
B@ConditionalOnMissingBean(name = "my.feature.enabled")
C@EnableConfigurationProperties(MyFeatureProperties.class)
D@ConditionalOnClass(name = "my.feature.enabled")
Step-by-Step Solution
Solution:
  1. Step 1: Identify annotation for property-based condition

    @ConditionalOnProperty activates config only if specified property matches given value.
  2. Step 2: Check other options

    @ConditionalOnMissingBean checks bean presence, not properties. @EnableConfigurationProperties binds properties but does not conditionally activate. @ConditionalOnClass checks class presence.
  3. Final Answer:

    @ConditionalOnProperty(name = "my.feature.enabled", havingValue = "true") -> Option A
  4. Quick Check:

    Property-based activation = @ConditionalOnProperty [OK]
Quick Trick: Use @ConditionalOnProperty to enable config by property value [OK]
Common Mistakes:
  • Using @ConditionalOnMissingBean for properties
  • Confusing @EnableConfigurationProperties with conditional activation
  • Using @ConditionalOnClass incorrectly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes