예제 3-16 컴포넌트 스캐닝 범위를 지정한 XML 구성 파일([[setter-injection]] app-context-annotation.xml)
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:c="http://www.springframework.org/schema/c" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <context:component-scan base-package="com.apress.prospring5.ch3.annotated"/> <context:exclude-filter type="assignable" expression="com.example.NotAService"/> </context:component-scan> </beans>
<context:component-scan> 태그는 지정한 패키지를 스프링에게 스캔하도록 지시하지만, 스캔에서 제외할 대상(클래스 또는 인터페이스)을 expression의 값으로 지정해 원하는 클래스를 스캔 대상에서 제외할 수 있습니다. 제외시키는 exclude 필터 외에도 포함시키는 include 필터를 사용할 수도 있습니다. 그리고 type의 값으로 annotation, regex, assignable, AspectJ, custom(org.springframework.core.type.filter.TypeFilter를 직접 구현한 사용자 필터 클래스) 등을 지정해 필터 기준으로 사용할 수 있습니다. expression은 지정한 type에 따라 다릅니다.