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.
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 2 years, 4 months agoSuman2409
Most Recent 2 weeks agostefumies
8 months, 2 weeks ago[Removed]
9 months, 2 weeks agoExamtopics_admin
1 year, 4 months agonesreenmhd123
1 year, 6 months agoAncient1
1 year, 8 months agozakupower
2 years, 2 months ago