반응형

- Autowiring 이란
  Spirng container가 bean 간의 참조관계를 자동으로 연결해주는 기능

- 속성값
 1. no : 기본값
 2. byName : property 명과 동일한 id 또는 name을 가진 bean
 3. byType : 동일한 클래스타입,(같은 타입 여러개 존재시 exception 발생)
 4. constructor : byType과 비슷하나 생성자인자에 적용
 5. autodetect : constructor 모드 수행후 byType 모드 수행
 6. default : 최상위 태그인 <beans> 에 셋팅한 모드가 수행됨. (default-autowire 속성)


Setter Injection 사용시

  1. <bean id="firstBean" class="“org.anyframe.exercise.dependencies.FirstBean">
  2.     <property name="”secondBean”" ref="”secondBean”/"></property></bean>
  3.     <bean id="secondBean" class="“org.anyframe.exercise.dependencies.SecondBean/">
  4. </bean>
Autowire 사용시
  1. <bean id="firstBean" class="“org.anyframe.exercise.dependencies.FirstBean" autowire="byType">
  2.     <bean id="secondBean" class="“org.anyframe.exercise.dependencies.SecondBean/">
  3. </bean></bean>

특정 bean을 autowiring 제외시키려면

  1. <bean id="bean" class="“org.anyframe.test.TestBean”" autowire-candidate="false"> </bean>


728x90
반응형

'Development > Java' 카테고리의 다른 글

[Spring]Spring Annotation  (0) 2012.08.01
[Spring]SpEL(Spring Expression Language)  (0) 2012.07.31
[Spring]AOP 주요 구성요소  (0) 2012.04.13
[Spring]Spring Bean Scope  (0) 2012.04.09
[Spring]Dependency Injection  (0) 2012.03.21
반응형
스프링은 4종류의 와이어링을 제공한다.

1. byName (autowire="byName")
    property 이름과 동일한 빈을 와이어링 해준다.
    이름이 반드시 같아야한다.

2. byType
    property type과 동일한 빈을 와이어링 해준다.
    할당 가능한 타입의 빈이 둘 이상일 경우에는 예외 발생시킨다.

3. constructor
   해당 빈의 생성자에 맞는 빈을 자동으로 선택해준다.

4. autodetect
    컨테이너가 알아서 결정해준다.
    최초에는 constructor 방식을 먼저 적용, 그다음에 byType 방식을 시도한다.

오토와이어링 문제점.
- 명확성 결여된다. 
728x90
반응형

+ Recent posts