spring2.0 标签

 
spring2.0 中支持 XML Schema 同时继续支持 dtd ,这样在 xml 配置文件中可以使用 dtd schema 两种方式进行声明,示例如下:
spring2.0 及之前版本均支持 dtd 声明:
<? xml version="1.0" encoding="UTF-8" ?>
<! DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd" >
< beans >
//这里是bean的配置
</ beans >

spring2.0
及以后版本支持 schema 声明:
<? xml version="1.0" encoding="UTF-8" ?>
<? xml version="1.0" encoding="UTF-8" ?>
< beans  xmlns ="http://www.springframework.org/schema/beans"
 xmlns:xsi
="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation
="http://www.springframework.org/schema/beans 
 http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"
>
//这里是bean的配置
</ beans >

spring2.0
可以新增 <util> 标签进行扩充,使用 <util:list> <util map> <util:set> <util:properties> 等标签可以取代并简化集合的配置,下面就 4 种标签分别举例说明:
在使用 <util> 标签之前首先要给 xml 配置文件中加入 util 的命名空间,增加后的 spring 配置文件头如下:
<? xml version="1.0" encoding="UTF-8" ?>
<? 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"
 xsi:schemaLocation
="http://www.springframework.org/schema/beans
  http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/util
  http://www.springframework.org/schema/util/spring-util-2.0.xsd "
>
……
</ beans >

给上面的各种集合配置修改成
<util > 如下:
1 list 配置:
<!--  配置一个人物角色  -->
    
< bean  id ="role"  class ="spring.chapter2.setDemo.Role" >
       
< property  name ="name"  value ="Mary"   />
       
< property  name ="health"  value ="100"   />
       
< property  name ="goods" >
           
< list >
              
< ref  bean ="medicine"   />
              
< ref  bean ="medicine1"   />
           
</ list >
       
</ property >
    
</ bean >

修改成
<util:list> 配置:
<!--  配置一个人物角色  -->
< util:list  id ="medicinelist" >
         
< ref  bean ="medicine"   />
< ref  bean ="medicine1"   />
</ util:list >
    
< bean  id ="role"  class ="spring.chapter2.setDemo.Role" >
       
< property  name ="name"  value ="Mary"   />
       
< property  name ="health"  value ="100"   />
       
< property  name ="goods"  ref ="medicinelist" >

<util:list>
标签可以使用 list-class 来指定的 list 作为使用的集合对象:
    <util:list id="medicinelist" list-class="java.util.ArrayList">
2 set 配置
<!--  配置一个人物角色  -->
    
< bean  id ="role"  class ="spring.chapter2.setDemo.Role" >
       
< property  name ="name"  value ="Mary"   />
       
< property  name ="health"  value ="100"   />
       
< property  name ="goods" >
           
< set >
              
< ref  bean ="medicine"   />
              
< ref  bean ="medicine1"   />
           
</ set >
       
</ property >
    
</ bean >
修改成 <util:set> 配置:
<!--  配置一个人物角色  -->
< util:set  id ="medicineset" >
            
< ref  bean ="medicine"   />
           
< ref  bean ="medicine1"   />
</ util:set >
    
< bean  id ="role"  class ="spring.chapter2.setDemo.Role" >
       
< property  name ="name"  value ="Mary"   />
       
< property  name ="health"  value ="100"   />
       
< property  name ="goods"  ref ="medicineset" />
    
</ bean >
< util:set >

标签也可以使用
set-class 来指定使用的集合容器对象:
<util:set id= "medicineset" set-class="java.util.TreeSet" >
3 map 配置 :
<!--  配置一个人物角色  -->
    
< bean  id ="role"  class ="spring.chapter2.setDemo.Role" >
       
< property  name ="name"  value ="Mary"   />
       
< property  name ="health"  value ="100"   />
       
< property  name ="goods" >
           
< map >
              
< entry  key ="key1" >
                     
< value > 小药丸 </ value >
</ entry >
< entry  key ="key2" >
                     
< value > 大药丸 </ value >
</ entry >
 
           
</ map >
       
</ property >
    
</ bean >

修改成
<util:map> 配置:
<!--  配置一个人物角色  -->
< util:map  id ="medicinemap" >
   
< entry  key ="key1"  value ="小药丸" />
< entry  key ="key2"  value ="大药丸" />
</ util:map >
    
< bean  id ="role"  class ="spring.chapter2.setDemo.Role" >
       
< property  name ="name"  value ="Mary"   />
       
< property  name ="health"  value ="100"   />
       
< property  name ="goods"  ref ="medicinemap" />
   
</ bean >
 
可以使用 map-class 来指定使用的集合对象
4 properties 配置:
<!--  配置一个人物角色  -->
    
< bean  id ="role"  class ="spring.chapter2.setDemo.Role" >
       
< property  name ="name"  value ="Mary"   />
       
< property  name ="health"  value ="100"   />
       
< property  name ="goods" >
           
< props >
           
< propkey ="key1" > 小药丸 </ prop >
            
< propkey ="key1" > 大药丸 </ prop >
         
</ props >
     
</ property >
    
</ bean >

修改成
<util:properties> 配置如下:
<!--  配置一个人物角色  -->
< util:properties  id ="medicineprops" >
   
< prop  key ="key1"  value ="小药丸" />
   
< prop  key ="key1"  value ="大药丸" />
</ util:properties  >
    
< bean  id ="role"  class ="spring.chapter2.setDemo.Role" >
       
< property  name ="name"  value ="Mary"   />
       
< property  name ="health"  value ="100"   />
       
< property  name ="goods"  ref ="medicineprops" />
    
</ bean >

<util:properties>
可以使用 location 标签来载入外部 properties 文件:
<util:properties id= "medicineprops" location="classpath:config.properties"/ >
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值