스프링 ComponentScan 관련 질문

23.01.04 16:34 작성 조회수 158

0

안녕하세요 초급개발자입니다.

최근 전자정부표준프레임워크 기반으로 개발된 어떤 소스를 보면서 componentScan에 관해 궁금한것이있었습니다.

우선, WEB-INF 아래의 dispatcher-servlet.xml에 명시되어있는 componentScan에는 Controller가 include 되어있고, service와 repository가 exclude 되어있습니다.


<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"/>


제가 알기로는 controller, service, repository 어노테이션에는 component 어노테이션이 포함되어있어서 component scan시 전부 bean으로 올리는 것으로 알고있는데 저렇게 exclude를 해놓으면 빈으로 등록이 안되는것 아닌가요 ?

basepackage는 최상위 디렉터리가 맞습니다.

 

또한, web.xml에 명시되어있는 다른 설정 xml파일도 있는데(context-common.xml) 이 파일에도 componenScan이 있습니다.

basepackage는 dispatcher-servlet에 명시되어있는 값과 같고, exclude filter로 컨트롤러는 빈 으로 올리지 않는다고 되어있습니다. 그리고 default filter는 따로 설정 해놓지 않아서 default 값인 true로 되어있기 때문에 기본 어노테이션(서비스, 레포지토리)는 빈으로 올린다고 알고 있습니다.


<context:exclude-filter expression="org.springframework.stereotype.Controller" type="annotation"/>

 


결론으로는 두 개의 컴포넌트 스캔(dispatcher-servlet.xml, context-common.xml)의 스캔 조건이 상반되게 되어있는데, 왜 그런지 이유가 궁금합니다 ....

답변 0

답변을 작성해보세요.

답변을 기다리고 있는 질문이에요.
첫번째 답변을 남겨보세요!