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.)
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.)
A . Ensure a valid bean name in the @Component annotation is specified.
B . Ensure a valid @ComponentScan annotation in the Java configuration is specified.
C . Ensure a valid @Scope for the class is specified.
D . Ensure a valid @Bean for the class is specified.
Answer: B
Explanation:
The @Component annotation indicates that a class is a candidate for auto-detection by Spring and can be registered as a bean in the application context. However, to enable this feature, the Java configuration class must also have the @ComponentScan annotation, which tells Spring where to look for annotated components.
Reference: https://docs.spring.io/spring-framework/docs/current/reference/html/core.html#beans-stereotype-annotations
Latest 2V0-72.22 Dumps Valid Version with 60 Q&As
Latest And Valid Q&A | Instant Download | Once Fail, Full Refund