Web/Spring 2018. 7. 10. 20:37

스프링프레임워크 util schema


spring xml 빈설정을 할때 util 스키마를 이용하여 List,Map,Set,Property 타입 등 여러가지 타입들을 빈으로 노출시킬 수 있는 기능을 제공해준다.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<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"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd 
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd">
 
    <bean id="bankDetails" class="sample.spring.chapter03.beans.BankDetails"> <property name="bankName" value="My Personal Bank" /> <property name="bankPrimaryBusiness" value="Retail banking" /> <property name="headOfficeAddress" value="Address of head office" /> <property name="privateBank" value="Y" /> <property name="primaryCurrency" value="INR" /> <property name="dateOfInception" ref="dateType" /> <property name="branchAddresses" ref="branchAddresses" /> </bean>

<util:properties id="propertiesType"
        location="classpath:META-INF/sample1.properties" />
    <util:properties id="anotherPropertiesType"
        location="classpath:META-INF/sample2.properties" />
    <util:list id="listType" list-class="java.util.ArrayList">
        <value>A simple String value in list</value>
        <value>Another simple String value in list</value>
    </util:list>
    <util:map id="mapType" map-class="java.util.TreeMap">
        <entry key="map key 1" value="map key 1’s value" />
    </util:map>
    <util:set id="setType" set-class="java.util.HashSet">
        <value>Element 1</value>
        <value>Element 2</value>
    </util:set>
</beans>
cs



이런식으로 빈으로 노출시켜서 빈정의에서 참조할 수 있다. 여기서 기본적으로 빈정의 안에서도 <list> 태그를 사용할 수 있는데 라는 이야기가 나올 수 있다. 하지만 util 스키마를 쓰면서의 장점은 list-class 속성으로 명시적으로 타입을 지정해줄 수 있어서 타입의 안정성이 있다는 것이다. 

posted by 여성게
: