* autoweire

autoweire 속성을 사용하여 스프링컨테이너가 조건에 만족하는 객체를 찾을 수 있도록 설정해준다

 

byType, byName 을 이용하여 의존 객체를 자동으로 가져올 수 있다

autoweire="byType"  : 같은 자료형을 갖는 객체를 가져온다

autoweire="byName"  : 같은 이름을 갖는 객체를 가져온다

 

 

xml 파일

<!--byType-->
<bean name="typeTest" class="spring.TypeTest" autowire="byType"/>     
<bean name="apple" class="spring.Apple"/>

<!--byName-->
<bean name="nameTest" class="spring.NameTest" autowire="byName"/>     
<bean name="apple" class="spring.Apple"/>

 

-> byType

TypeTest 클래스에는 Apple클래스 객체 자료형의 초기값을 설정해주는 setter 메소드가 존재한다

autowire 속성을 통해 같은 자료형인 Apple클래스 객체를 얻어와 의존성 주입을 자동으로 해준다

 

-> byName

autowire 속성을 통해 TypeTest 클래스의 멤버변수 이름과 apple이 같으므로 의존성 주입을 자동으로 해준다

 


추상( abstract="true" )

추상클래스임을 알려주는 옵션으로 해당 클래스의 빈객체를 생성하지 않는다

<bean id="test" class="Test" abstract="true">
     <property name="time" value="10"/>
     <property name="count" value="5"/>
</bean>

 


상속관계

Cake(부모클래스) - CheeseCake(자식클래스) 라고 했을때, 

 

<!--부모 빈즈-->
<bean id="cake" class="spring.Cake">
	<property name="count" value="5"/>
</bean>

<!--자식 빈즈-->
<!--부모의 멤버변수 그대로 사용  -->
<bean id="cheese1" parent="cake" />

<!--오버라이딩 -->
<bean id="cheese2" parent="cake">
    <property name="count" value="10" />
</bean>

 

-> 이때 parent="부모 빈즈의 id 혹은 name" 을 부여한다.

 

+ Recent posts