2012-12-19 2 views
3

@PostConstruct를 사용하려면 스프링 3에서 <context:annotation-config><context:component-scan>을 정의해야합니까? applicationContext.xml<context : annotation-config> 및 <context : component-scan>

<context:component-scan base-package="net.test" /> 

........ 
... 

<context:annotation-config /> 

나는 나의 ManagedBean은의 방법 getLazyLoad을하고 난이 콩에 대한 @PostConstruct를 사용하고 싶습니다. 당신의 context.xml과 @PostConstruct, @Autowired, @Resource 그리고 봄 지원이 처리 될 다른 주석에서 빈을 인스턴스화 할 수 있습니다 그 후

감사

답변

2

@Component

<context:component-scan base-package="net.test" /> 

에 관련된 클래스 레벨에서 모든 주석을 가진되지 않아도됩니다.

@PostConstruct으로 작업하려면 <context:annotation-config />이면 충분합니다.

EDIT1 : 여러분의 빈 다음 <context:component-scan />는 지정된 패키지 미만 빈을 검색합니다

@Component, @Repository, @Service, or @Controller. 

주석

아래 어떤가있는 경우

suspose.

+0

패키지를 검사하려면''가 필요합니까? – user75ponic

+0

내 편집보기 참조 – NPKR

+0

설명에 감사드립니다. – user75ponic

3

<context:annotation-config>은 충분하다. 구성 요소 스캔 주석을 사용하는 경우 참고 - 구성 모드는 기본적으로 활성화되어 있습니다. 여러분의 빈에서

+0

패키지를 검사하려면''가 필요합니까? – user75ponic

+0

예. 이 두 가지 '명령'은 분리되어 있습니다. –

+0

감사합니다. – user75ponic