Exam 2v0-7222 All QuestionsBrowse all questions from this exam
Question 1

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.)

    Correct Answer: B

    To have Spring automatically detect a class annotated with @Component and load it as a bean, you need to ensure a valid @ComponentScan annotation in the Java configuration. The @ComponentScan annotation tells Spring where to look for classes annotated with @Component (as well as other stereotype annotations such as @Service, @Repository, and @Controller) within the specified packages. Without this, Spring will not scan the specified packages for annotated classes.

Discussion
faciorysOption: B

To autodetect these classes and register the corresponding beans, you need to add @ComponentScan to your @Configuration class https://docs.spring.io/spring-framework/docs/current/reference/html/core.html#spring-core

zakupowerOption: B

Valid bean name is provided for you using the name of the class, @ComponentScan on a @Configuration marked class is needed.

nesreenmhd123Option: B

B is the correct answer: https://www.baeldung.com/spring-component-annotation

Evoila_TrainingMaterialOption: B

B. Ensure a valid @ComponentScan annotation in the Java configuration is specified. This is the correct answer. The @ComponentScan annotation tells Spring where to look for classes annotated with @Component (and other stereotype annotations like @Service, @Repository, and @Controller). Without this, Spring will not know to scan the specified packages for annotated classes.

Examtopics_admin

Test to be

Ancient1Option: B

In order for spring to find the beans, you need to add @ComponentScan