예제 3-15 컴포넌트 스캐닝 설정을 한 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"/> </beans>
<context:component-scan> 태그는 지정한 패키지의 모든 하위 패키지에 있는 클래스에 선언된 @Autowired, @Inject, @Resource 애너테이션뿐만 아니라 @Component, @Controller, @Repository, @Service 애너테이션이 선언된, 의존성 주입이 가능한 빈의 코드를 스캔하도록 스프링에 지시합니다. <context:component-scan> 태그에서 쉼표, 세미콜론, 공백을 구분 기호로 사용해 여러 패키지를 정의할 수 있습니다. 또한, 이 태그에서는 컴포넌트 스캔의 범위와 제외 범위를 지정해 스캔 범위를 정밀하게 제어할 수 있습니다. 다음 예제를 살펴보겠습니다.