반응형
Notice
Link
스택큐힙리스트
context:annotation-config>와 <context:component-scan>의 차이점 본문
반응형
저는 Spring 3를 배우고 있는데 <context:annotation-config>
와 <context:component-scan>
의 기능을 이해하기 어렵습니다.
읽은 내용에 따르면, 이들은 다른 주석 (@Required
, @Autowired
등 vs @Component
, @Repository
, @Service
등)를 다룬다고 합니다. 하지만, 같은 빈 후처리기 클래스를 등록한다는 내용도 읽었습니다.
더 혼란스럽게, <context:component-scan>
에는 속성으로 annotation-config
가 있습니다.
이 태그들에 대해 어떤 점이 유사한지, 어떤 점이 다른지, 다른 태그가 다른 태그에게 우선되는지, 둘이 서로 보완되는지, 둘 중 하나를 필요로 하는지 또는 둘 다 필요한지에 대해 알려주실 수 있는 분이 있을까요?
답변 1
스프링은 사용자가 처리 도구를 여러 번 등록하더라도, 그것들이 단 한 번만 실행되도록 보장합니다. 다음 XML:
<context:annotation-config />
<context:component-scan base-package=com.xxx />
<bean id=aBean class=com.yyy.A />
<bean id=bla class=org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor />
<bean id=bla1 class=org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor />
<bean id=bla2 class=org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor />
<bean id=bla3 class=org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor />
아래와 같은 결과를 생성합니다:
빈 B를 생성 중: com.xxx.B@157aa53
빈 C를 생성 중: com.xxx.C@ec4a87
빈 A를 생성 중: com.yyy.A@25d2b2
A.bbb를 com.xxx.B@157aa53로 설정 중
A.ccc를 com.xxx.C@ec4a87로 설정 중
좋아요, 이로써 마무리입니다.
이 정보와 @Tomasz Nurkiewicz 및 @Sean Patrick Floyd의 응답들을 통해 <context:annotation-config>
와 <context:component-scan>
이 어떻게 작동하는지 이해하실 수 있을 것입니다.
답변 2
Spring은 자바 기반의 애플리케이션을 개발하기 위한 유연하고 강력한 프레임워크로 널리 알려져 있다. Spring은 개발자들이 애플리케이션을 구축하고 관리하는 데 필요한 다양한 기능을 제공한다. 이 중에서도
먼저,
한편,
주목할만한 차이점은
요약하자면,
반응형
Comments