java [ Spring ] @Annotation Component Scan

java [ Spring ] @Annotation Component Scan

@Controller, @Service, @Repository, @Component 등의

@Annotation을 component-scan을 xml에 선언해서 사용.

...

디폴트(@Component, @Controller, @Service, @Repository) 어노테이션을 스캔하지 않는 방법도 있는데, use-default-filters를 이용하면 된다. 기본값은 true이기 때문에 false로 선언해주면 디폴트 어노테이션들을 스캔하지 않는다.

Component Scan은 XML에 매번 빈 등록을 하지 않고 클래스에 특정 어노테이션을 적용함으로써 자동으로 빈 등록이 되게끔 해준다.

//servlet-context.xml

.xml 파일

@Controller 를 제외하고 싶다면 위와 같이 exclude-filter를 사용하여

org.springframework.stereotype.Controller를 명시해준다.

1. exclude-filter 2. include-filter

.java 파일 설정

@Configuration @ComponentScan(basePackages = "com.rcod.lifelog") public class ApplicationConfig { }

https://fbtmdwhd33.tistory.com/261

https://velog.io/@hyun-jii/%EC%8A%A4%ED%94%84%EB%A7%81-component-scan-%EA%B0%9C%EB%85%90-%EB%B0%8F-%EB%8F%99%EC%9E%91-%EA%B3%BC%EC%A0%95

from http://hhnee.tistory.com/113 by ccl(A) rewrite - 2021-12-13 21:01:07