component-scan
Spring 2013. 9. 16. 12:46 |ㅇ <bean> 형태로 Bean 객체를 선언하지 않고 조건에 맞는 클래스를 자동으로 읽어들이는 (Bean 객체 선언) 방법
ㅇ 사용방법
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:component-scan base-package="com.spring.autowired.exam3">
<context:include-filter type="assignable" expression="com.spring.autowired.exam3.First"/>
<context:include-filter type="assignable" expression="com.spring.autowired.exam3.Second"/>
</context:component-scan>
</beans>
스프링 MVC의 @Controller, @Service, @Repository, @Component 등 기본 지원 애노테이션은 자동으로 등록하지만
개발자가 별도로 만든 클래스를 자동으로 등록되지 않음
위의 경우는 assignable 이라는 옵션을 사용하여 해당 클래스를 직접 등록
보통은 위처럼 사용하지 않고 <context:component-scan base-package="패키지 경로" /> 까지만 적용해도 상관없음
<context:component-scan> 을 적용하는 경우는 <context:annotation-config /> 태그를 사용하지 않아도 됨
예제 파일
'Spring' 카테고리의 다른 글
스프링을 사용한 파일 업로드 1 (1) | 2014.03.04 |
---|---|
web.xml 설정 (0) | 2013.10.07 |
Autowired (0) | 2013.09.16 |
기본 데이터 / Bean 객체 주입 방법 (0) | 2013.09.16 |
스프링 개념(?) (0) | 2013.09.16 |