Sobes.tech
Junior — Middle

What does the @ComponentScan annotation in Spring check and how?

sobes.tech AI

Answer from AI

The @ComponentScan annotation in Spring indicates to the framework which packages to scan for classes annotated with component annotations such as @Component, @Service, @Repository, @Controller.

It automatically scans the specified packages and registers the found beans in the Spring context, allowing their use through dependency injection.

Example of usage:

@Configuration
@ComponentScan(basePackages = "com.example.app.services")
public class AppConfig {
}

In this example, Spring will scan the package com.example.app.services and all its subpackages for components to register.

What does the @ComponentScan annotation in Spring… - sobes.tech