Bird
0
0

Which of the following is the correct way to enable @ConfigurationProperties support in a Spring Boot application?

easy📝 Syntax Q12 of 15
Spring Boot - Application Configuration
Which of the following is the correct way to enable @ConfigurationProperties support in a Spring Boot application?
AAdd <code>@RestController</code> on the configuration class
BAnnotate the class with <code>@Entity</code>
CAnnotate the class with <code>@Component</code> or use <code>@EnableConfigurationProperties</code> on a configuration class
DUse <code>@Service</code> annotation on the properties class
Step-by-Step Solution
Solution:
  1. Step 1: Identify how Spring Boot detects @ConfigurationProperties classes

    Spring Boot requires the class to be a Spring bean, which can be done by annotating it with @Component or by enabling it via @EnableConfigurationProperties.
  2. Step 2: Recognize incorrect annotations

    @Entity is for JPA entities, @RestController is for web controllers, and @Service is for service layer beans, none of which enable configuration properties binding.
  3. Final Answer:

    Annotate the class with @Component or use @EnableConfigurationProperties on a configuration class -> Option C
  4. Quick Check:

    Enable with @Component or @EnableConfigurationProperties [OK]
Quick Trick: Use @Component or @EnableConfigurationProperties to activate binding [OK]
Common Mistakes:
  • Using @Entity or @RestController instead of @Component
  • Forgetting to register the properties class as a bean
  • Assuming @Service enables configuration binding

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes