nerdexam
Broadcom-VMware

2V0-72.22 · 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.

Application Deployment and Management

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

(28 responses)
  • A
    4% (1)
  • B
    86% (24)
  • C
    7% (2)
  • D
    4% (1)

Explanation

To autodetect these classes and register the corresponding beans, you need to add @ComponentScan to your @Configuration class.

Topics

#@Component#@ComponentScan#Spring bean#dependency injection

Community Discussion

No community discussion yet for this question.

Full 2V0-72.22 Practice