-
Component와 ComponentScan 정리SPRING 2020. 4. 10. 00:18
컴포넌트 스캔
● 설정 방법
- XML 설정에서는 context:component-scandisPatcher-servlet.xml에 아래와 같이 componentScan을 설정한다.
base-package에 속하는 패키지들의 componet들을 scan하여 빈으로 등록함.
123456789<context:include-filter type="annotation"expression="org.springframework.stereotype.Controller" /><context:include-filter type="annotation"expression="org.springframework.stereotype.Service" /><context:include-filter type="annotation"expression="org.springframework.stereotype.Repository" /></context:component-scan>http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter- 자바 설정에서 @ComponentScan
스프링 부트에서는 @SpringBootApplication 가 @Component 어노테이션을 포함하고 있음.
● 특정 패키지 이하의 모든 클래스 중에 @Component 애노테이션을 사용한 클래스를 빈으로 자동으로 등록 해 줌.
@Component 의 종류
- @Repository : Dao 단을 구성하는 Component
- @Service : Service(비즈니스 로직)단을 구성하는 Component
- @Controller : Controller
- @Configuration'SPRING' 카테고리의 다른 글
스프링 프로파일 (Profile) (0) 2020.04.14 스프링 빈 스코프 (싱글톤, 프로토타입) (0) 2020.04.12 @Autowired 심화 학습(자료 : 백기선) (0) 2020.04.06 AOP (Aspect Oriented Programming) (자료: 백기선) (0) 2020.03.23 DI 주입 방법(3가지) (0) 2020.03.23