Broadcom-VMware
2V0-72.22PSE · Question #30
If a class is annotated with @Component, what should be done to have Spring automatically detect the annotated class and load it as a bean? (Choose the best answer.)
The correct answer is B. Ensure a valid @ComponentScan annotation in the Java configuration is specified. To autodetect these classes and register the corresponding beans, you need to add @ComponentScan to your @Configuration class.
Core Spring
Question
If a class is annotated with @Component, what should be done to have Spring automatically detect the annotated class and load it as a bean? (Choose the best answer.)
Options
- AEnsure a valid bean name in the @Component annotation is specified.
- BEnsure a valid @ComponentScan annotation in the Java configuration is specified.
- CEnsure a valid @Scope for the class is specified.
- DEnsure a valid @Bean for the class is specified.
How the community answered
(53 responses)- A8% (4)
- B74% (39)
- C15% (8)
- D4% (2)
Explanation
To autodetect these classes and register the corresponding beans, you need to add @ComponentScan to your @Configuration class.
Topics
#@Component#@ComponentScan#bean detection#component scanning
Community Discussion
No community discussion yet for this question.