위에서 보이는 @Controller, @Repository, @Service 모두 내부에 @Component 어노테이션이 포함되어 있는 것을 볼 수 있다.
@Controller
@Target({ElementType.TYPE})@Retention(RetentionPolicy.RUNTIME)@Documented@Componentpublic @interfaceController {/** * The value may indicate a suggestion for a logical component name, * to be turned into a Spring bean in case of an autodetected component. * @return the suggested component name, if any (or empty String otherwise) */ @AliasFor(annotation =Component.class)Stringvalue()default"";}
@Repository
@Target({ElementType.TYPE})@Retention(RetentionPolicy.RUNTIME)@Documented@Componentpublic @interfaceRepository {/** * The value may indicate a suggestion for a logical component name, * to be turned into a Spring bean in case of an autodetected component. * @return the suggested component name, if any (or empty String otherwise) */ @AliasFor(annotation =Component.class)Stringvalue()default"";}
이렇게 @Component 어노테이션을 보고 스프링 빈으로 등록되는 것을 컴포넌트 스캔이라고 한다.