本文實例講述了Spring使用util:命名空間簡化配置操作。分享給大家供大家參考,具體如下:
一 配置
<?xml version="1.0" encoding="GBK"?> <!-- 指定Spring配置文件的根元素和Schema 導入p:命名空間和util:命名空間的元素 --> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:util="http://www.springframework.org/schema/util" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd"> <!-- 配置chinese實例,其實現類是Chinese --> <bean id="chinese" class="org.crazyit.app.service.impl.Chinese" p:age-ref="chin.age" p:axe-ref="stoneAxe" p:schools-ref="chin.schools" p:axes-ref="chin.axes" p:scores-ref="chin.scores"/> <!-- 使用util:constant將指定類的靜態Field定義成容器中的Bean --> <util:constant id="chin.age" static-field= "java.sql.Connection.TRANSACTION_SERIALIZABLE"/> <!-- 使用util.properties加載指定資源文件 --> <util:properties id="confTest" location="classpath:test_zh_CN.properties"/> <!-- 使用util:list定義一個List集合,指定使用LinkedList作為實現類, 如果不指定默認使用ArrayList作為實現類 --> <util:list id="chin.schools" list-class="java.util.LinkedList"> <!-- 每個value、ref、bean...配置一個List元素 --> <value>小學</value> <value>中學</value> <value>大學</value> </util:list> <!-- 使用util:set定義一個Set集合,指定使用HashSet作為實現類, 如果不指定默認使用HashSet作為實現類--> <util:set id="chin.axes" set-class="java.util.HashSet"> <!-- 每個value、ref、bean...配置一個Set元素 --> <value>字符串</value> <bean class="org.crazyit.app.service.impl.SteelAxe"/> <ref bean="stoneAxe"/> </util:set> <!-- 使用util:map定義一個Map集合,指定使用TreeMap作為實現類, 如果不指定默認使用HashMap作為實現類 --> <util:map id="chin.scores" map-class="java.util.TreeMap"> <entry key="數學" value="87"/> <entry key="英語" value="89"/> <entry key="語文" value="82"/> </util:map> <!-- 配置steelAxe實例,其實現類是SteelAxe --> <bean id="steelAxe" class="org.crazyit.app.service.impl.SteelAxe"/> <!-- 配置stoneAxe實例,其實現類是StoneAxe --> <bean id="stoneAxe" class="org.crazyit.app.service.impl.StoneAxe"/> </beans>
網站題目:Spring實戰之使用util:命名空間簡化配置操作示例-創新互聯
文章轉載:http://vcdvsql.cn/article34/jegpe.html
成都網站建設公司_創新互聯,為您提供服務器托管、品牌網站設計、App設計、企業建站、網站排名、域名注冊
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯