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.
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
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.
Valid bean name is provided for you using the name of the class, @ComponentScan on a @Configuration marked class is needed.
upvoted 3 times
...
Log in to ExamTopics
Sign in:
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
faciorys
Highly Voted 1 year, 11 months agostefumies
Most Recent 3 months, 1 week agoEvoila_TrainingMaterial
4 months, 1 week agoExamtopics_admin
11 months, 3 weeks agonesreenmhd123
1 year, 1 month agoAncient1
1 year, 3 months agozakupower
1 year, 8 months ago