강의

멘토링

커뮤니티

인프런 커뮤니티 질문&답변

신입개발자가되고싶어님의 프로필 이미지
신입개발자가되고싶어

작성한 질문수

3. 웹개발 코스 [스프링 프레임워크+전자정부 표준프레임워크]

제3강 Spring MVC패턴

안녕하세요 영상에 나온 component-scan관련 추가질문

작성

·

756

0

component-scan관련해서, dispatcher.xml에 'component-scan'은 @Controller만 include해놨고, 뭐, context.common.xml에서는 @Controller만 exclude해놨잖아요. 굳이 이렇게 나눈 이유는 설명을 듣지못해서, 구글링했는데도 잘 모르겠네요. 현 강의에서는 안나오고, 뒤에서 설명해주시는건가요? 이부분 설명좀 해주시면 감사하겠습니다.  

아 참고로, component-scan이 무슨 기능인지, include가 포함시키고 exclude가 제외시킨다는 의미까지는 알고있습니다.  예상하자면, @Retention에서 쓰이는 속성의 RetentionPolicy와 유사한 이유인가요? 

 

 

2.  2번쨰로는 dispatcher.xml을 action으로 놔두는건 약속인가요?  *.do도 전자정부프레임워크의 약속인가요? 

(개발자가 마음대로 바꿔도 오류가 안나는건 알고있습니다 ㅎㅎ) 

답변 1

1

개발자Park님의 프로필 이미지
개발자Park
지식공유자

안녕하세요.

1. 

dispatcher.xml에 'component-scan'은 @Controller만 include해놨고

context.common.xml에서는 @Controller만 exclude해놨잖아요. 

=>

component-scan:@Controller만 include해당부분을 통해 dispatcher.xml에서 Controller를 사용할 수 있도록 했습니다.

그외의 ServiceLayer영역(5강의 25분참조)도 필요하다면 이런식으로 변경하셔도 무관합니다.

 

<context:component-scan base-package="egov">

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

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

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

</context:component-scan>

 

강의처럼 @Controller만을 포함한경우

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

 

@Service와 @Repository를 이용하는 .xml에서는 @Controller애노테이션을 스캔할 필요가없기에(이미 dispatcher.xml에서 빈으로 등록되어 사용자 요청url을 접수했기에)context.common.xml에서

    <context:component-scan base-package="egov">

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

    </context:component-scan>

가 사용되었습니다.

  

2. action또는 .do를 임의로 변경하셔도 상관없습니다.

단 그에 맞게 나머지 설정도 해주셔야합니다.

 

감사합니다.

답변 감사합니다. 

선생님 구글링해도 안나오던데, 위 질문에서 말한것과 같이 component-scan 관련 질문인데요.

dispatcher.xml에서 사용자 url을 요청받기 위해 @Controller를 include한것은 이해했습니다. 하지만 나머지 @Service와 @Repository 는 exclude한 이유는 뭔가요? dispatcher가 읽히는 단계에서 굳이 필요없기도하고, 메모리 낭비만 되기때문에 exclude한건가요? 

개발자Park님의 프로필 이미지
개발자Park
지식공유자

네. 필요없기에 exclude를 했습니다.

만약에 사용하실려면 include하셔도 무관합니다.

신입개발자가되고싶어님의 프로필 이미지
신입개발자가되고싶어

작성한 질문수

질문하기