Bird
0
0

You want to create a custom auto-configuration that only activates if a specific class is on the classpath. Which annotation should you use?

hard📝 Application Q8 of 15
Spring Boot - Fundamentals
You want to create a custom auto-configuration that only activates if a specific class is on the classpath. Which annotation should you use?
A@ConditionalOnClass
B@EnableAutoConfiguration
C@ComponentScan
D@ConfigurationProperties
Step-by-Step Solution
Solution:
  1. Step 1: Identify the conditional annotation for class presence

    @ConditionalOnClass activates configuration only if the specified class is present on the classpath.
  2. Step 2: Differentiate from other annotations

    @EnableAutoConfiguration enables auto-config globally; @ComponentScan scans beans; @ConfigurationProperties binds properties.
  3. Final Answer:

    @ConditionalOnClass -> Option A
  4. Quick Check:

    Use @ConditionalOnClass to activate config by class presence [OK]
Quick Trick: Use @ConditionalOnClass to conditionally enable auto-config [OK]
Common Mistakes:
  • Confusing @EnableAutoConfiguration with conditional activation
  • Using @ComponentScan to control auto-config activation
  • Misusing @ConfigurationProperties for conditional logic

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes