2011-04-14 3 views
12

스프링은 어떻게합니까? @Autowire beans : byName 또는 byType? 가능하지 않은 경우 다른 모드를 사용하여 두 번째 시도가 완료됩니까?@ 자동 기본 모드

답변

24

@Autowired으로 주석 처리 된 경우 일치 유형의 빈을 삽입합니다 (유형이 두 개 이상있는 경우 예외가 발생 함). 이름을 지정하려면 @Qualifier 주석을 사용하십시오.

3

스프링 @Autowire 유형별 전선. 이름으로 배선을 위해 당신은 또한

@Resource(name = "id") 
1

@Autowired의 기본 모드는 byType되어 사용할 수 있습니다. 변수 또는 세터 방법에

+1

로 defaut에가의 @Autowired의 기본 모드는 '더'아니오에서 autowiring이없는 것입니다 공연. 다른 bean에 대한 모든 참조는 명시 적으로 주입되어야합니다. 이것은 기본 모드입니다. – TheCyberXP

+2

기본적으로 '아니오'인 autowire 속성을 참조하고, @Autowired 어노테이션은 byType입니다 – jarosik

0

Autowired 주석이 XML 속성과 동일한 autowire="byType"

XML 속성 autowire이 False no

"no": 

The traditional Spring default. No automagical wiring. Bean references 
must be defined in the XML file via the <ref/> element (or "ref" 
attribute). We recommend this in most cases as it makes documentation 
more explicit. 
관련 문제