Bean 속성이나 생성자 인자를 List, Set 또는 Map의 다른 구현으로 대체하려는 경우가 있다.
예를 들어 List 형식의 빈 속성에 ArrayList 대신에 LinkedList의 인스턴스를 할당하려는 경우가 있다.
이 경우 스프링 util 스키마의 <list>, <map>, <set> 요소를 사용하는 것이 좋다.
이걸 사용하면 Bean의 List, Map, Set의 구현 클레스를 자신이 원하는 클레스로 지정할 수 있다.
Example XML
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
<util:list id="listType" list-class="java.util.ArrayList" value-type="java.lang.String">
<value>11</value>
<value>22</value>
</util:list>
<util:map id="mapType" map-class="java.util.HashMap" value-type="java.lang.String">
<entry key="aa" value="11" value-type="java.lang.String" />
<entry key="bb" value="22" value-type="java.lang.String" />
</util:map>
<util:set id="setType" set-class="java.util.HashSet" value-type="java.lang.String">
<value>11</value>
<value>22</value>
</util:set>
<util:properties id="propertyType">
<prop key="aa">11</prop>
<prop key="bb">22</prop>
</util:properties>
<bean class="CollectionProperty" p:pList-ref="listType" p:pMap-ref="mapType" p:pSet-ref="setType"
p:properties-ref="propertyType" />
</beans>
'Spring Framework' 카테고리의 다른 글
날짜 데이터 Injection (0) | 2017.07.06 |
---|