본문 바로가기
자바웹프로그래밍/전자정부프레임워크-번외

context:include-filter && context:exclude-filter&&context:componet-scan이란?

by 디찌s 2020. 11. 15.
728x90
반응형

 

<context:component-scan base-package="pet">
		<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
		<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Service"/>
		<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Repository"/>
</context:component-scan>

 

 

Context:componet-scan

- componet scan을 지원하는 태그이다.

- Bean이 될 수 있는 모든 Component들을 자동으로 찾아 Bean 컨테이너에 등록한다.

- 단, 의존성 관계 등록은 따로 하지않는다.

- 특정 패키지 안의 클래스들을 스캔하고, Annotation을 확인후 빈 인스턴스를 생성 @contorller @service         @repository @component 등의 bean 등록 Annotation이 존재하여야 빈을 스캔후 생성할수있다.

- @autowired와 @qualifier anootation을 인식할수있다.

- @commpoent를 통해 자동으로 빈등록하고, @autowired로 의존관계를 주입 받는 어노테이션을 클래스에서 선언하여 사용했을 경우에는 해당 클래스가 위치한 특정 패키지를 scan하기 위한 설정을 스프링 xml에 해주어야한다.

- component-scna을 선선하면 context:annotation-config를 선언할 필요가없다.

 

 

Context:include-filter & context:exclude-filter 

자동 스캔대상에 포함시킬 클래스와 포함시키지 않을 클래스를 구체적으로 명시할수있다.

 

 

스캔대상에 클래스를 포함

<!-- Controller 타입의 bean만 스캔해서 등록한다-->
<context:component-scan base-package="pet">
<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>

 

스캔대상에 클래스를 미포함

<!-- service,repository 타입을 제외한 모든 bean들을 root context에서 로딩한다 -->

<context:component-scan base-package="pet">
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Service"/>
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Repository"/>
</context:component-scan>
728x90
반응형

댓글