📌 스프링에서 컬렉션 의존성 주입의 util namespace 방법
[ list ]
- list 주입
- 자바코드 : List<Cat> catList;
- xml
<property name="catList"> <list> <ref bean="값1" /> <ref bean="값2" /> </list> </property>
- util namespace
<!-- util namespace --> <util:list id="xxx"> <ref bean="c1"/> <ref bean="c2"/> <ref bean="c1"/> </util:list> <bean id="service" class="com.service.UserService"> <property name="catList" ref="xxx" /> </bean>
[ set ]
- set 주입
- 자바코드: Set<Cat> catSet;
- xml :
<property name="catSet"> <set> <ref bean="값1" /> <ref bean="값2" /> </set> </property>
- util namespace
<!-- uttl namespace --> <util:set id="xxx"> <ref bean="c1"/> <ref bean="c2"/> <ref bean="c1"/> </util:set> <bean id="service" class="com.service.UserService"> <property name="catSet" ref="xxx"></property> </bean>
[ map ]
- map 주입
- 자바코드: Map<String,Cat> catMap;
- xml :
<property name="catMap"> <map> <entry key="" value-ref="값" /> <entry key=""> <ref bean="값" /> </entry> </map> </property>
- util namespace
<!-- util namespace --> <util:map id="xxx"> <entry key="pet01" value-ref="c1" /> <entry key="pet02"> <ref bean="c2"/> </entry> </util:map> <bean id="service" class="com.service.UserService3"> <property name="catMap" ref="xxx" /> </bean>
[ props ]
- props 주입 ⇒ key/value 쌍으로 저장, 저장하는 value값이 무조건 문자열이다.
- 자바코드: Properties xxx;
- xml :
<property name="xxx"> <props> <prop key="키">문자열값</prop> </props> </property>
- util namespace
<!-- util namespace --> <util:properties id="xxx"> <prop key="phone1">03112345678</prop> <prop key="phone2">0104567891</prop> </util:properties> <bean id="service2" class="com.service.UserService4"> <property name="phones" ref="xxx" /> </bean>
'Framework > SPRING FRAMEWORK' 카테고리의 다른 글
현재 실행중인 운영체제의 환경변수 값 살펴보기 (0) | 2023.08.29 |
---|---|
life cycle 콜백 메서드 (0) | 2023.08.29 |
03. DI_setter (0) | 2023.08.29 |
03. DI_constructor_c namespace와 p namespace (0) | 2023.08.28 |
03. DI_constructor_두 클래스 연동 (0) | 2023.08.28 |