Skip to content
Sharp

Spring Core · interview question

In a Spring Boot application, what is the main purpose of the @ComponentScan annotation?

Multiple choiceMediumchapter-9-curatedpremiumspring-corecontrollers-services-repositories
Choose one answer
Answer and explanation

Correct answer

A. To specify the packages to scan for annotated components.

Why

@ComponentScan is used to specify base packages to scan for Spring components, such as @Component, @Service, @Repository, and @Controller annotated classes. This allows Spring to detect and register these components as beans.

Test yourself on Spring Core

A free test with instant, explained results. No account needed.

Start free test
All Spring Core questions →