<span style="font-size:18px;">关于spring集合对象的补充 spring2.0中对集合对象有了改进,新增了一个<util>标签,这个标签在设置Bean定义时更为方便。 要使用改标签,必须要在配置文件中加入util名称空间,如: xmlns:util="http://www.springframework.org/schema/util" http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsc" 在头文件中加入以上代码就可以使用util标签了 util标签的使用: 1,<util:constant/> 取代了之前通过FieldRetrevingFactoryBean获取bean静态常量的FactoryBean! 老的用法 <bean id="..." class="..."> <property name="isolation"> <bean id="java.sql.Connection.TRANSACTION_SERIALIZABLE" class="org.springframework.beans.factory.config.FieldRetrievingFactoryBean" /> </property> </bean> 新用法 <bean id="..." class="..."> <property name="isolation"> <util:constant static-field="java.sql.Connection.TRANSACTION_SERIALIZABLE"/> </property> </bean> 2,<util:property-path/> 取代了之前通过PropertyPathFactoryBean来指定属性路径获取属性值的FactoryBean! 老的用法 <bean id="testBean" class="org.springframework.beans.TestBean" singleton="false"> <property name="age" value="10"/> <property name="spouse"> <bean class="org.springframework.beans.TestBean"> <property name="age" value="11"/> </bean> </property> </bean> <bean id="testBean.age" class="org.springframework.beans.factory.config.PropertyPathFactoryBean"/> 新的用法 <bean id="testBean" class="org.springframework.beans.TestBean" singleton="false"> <property name="age" value="10"/> <property name="spouse"> <bean class="org.springframework.beans.TestBean"> <property name="age" value="11"/> </bean> </property> </bean> <util:property-path id="name" path="testBean.age"/> 3,<util:properties/> 替代了之前通过PropertiesFactoryBean来获取properties配制文件数据的FactoryBean! 老用法 <bean id="jdbcConfiguration" class="org.springframework.beans.factory.config.PropertiesFactoryBean"> <property name="location" value="classpath:com/foo/jdbc-production.properties"/> </bean> 新用法 <util:properties id="jdbcConfiguration" location="classpath:com/foo/jdbc-production.properties"/> 4,<util:list/> 替代了之前通过<list><value></value></list>的内置配制方式,让多个bean调用同一list成为可能! 老的用法 <bean id="emails" class="org.springframework.beans.factory.config.ListFactoryBean"> <property name="sourceList"> <list> <value>pechorin@hero.org</value> <value>raskolnikov@slums.org</value> <value>stavrogin@gov.org</value> <value>porfiry@gov.org</value> </list> </property> </bean> 新的用法 <util:list id="emails" list-class="java.util.LinkedList"> <value>pechorin@hero.org</value> <value>raskolnikov@slums.org</value> <value>stavrogin@gov.org</value> <value>porfiry@gov.org</value> </util:list> 5,<util:map/> 替代了之前适用<map><entry key=""><value></value></entry></map>的配置方式,让多个bean调用同一map成为可能! 老的用法 <bean id="emails" class="org.springframework.beans.factory.config.MapFactoryBean"> <property name="sourceMap"> <map> <entry key="pechorin" value="pechorin@hero.org"/> <entry key="raskolnikov" value="raskolnikov@slums.org"/> <entry key="stavrogin" value="stavrogin@gov.org"/> <entry key="porfiry" value="porfiry@gov.org"/> </map> </property> </bean> 新的用法 <util:map id="emails" map-class="java.util.TreeMap"> <entry key="pechorin" value="pechorin@hero.org"/> <entry key="raskolnikov" value="raskolnikov@slums.org"/> <entry key="stavrogin" value="stavrogin@gov.org"/> <entry key="porfiry" value="porfiry@gov.org"/> </util:map> 6,<util:set/> 替代了之前适用<set><value></value></set>的配置方式, 让多个bean调用同一set成为可能! 老的用法 <bean id="emails" class="org.springframework.beans.factory.config.SetFactoryBean"> <property name="sourceSet"> <set> <value>pechorin@hero.org</value> <value>raskolnikov@slums.org</value> <value>stavrogin@gov.org</value> <value>porfiry@gov.org</value> </set> </property> </bean> 新的用法 <util:set id="emails" set-class="java.util.TreeSet"> <value>pechorin@hero.org</value> <value>raskolnikov@slums.org</value> <value>stavrogin@gov.org</value> <value>porfiry@gov.org</value> </util:set> 7,<jee:jndi-lookup/> 替代了之前使用JndiObjectFactoryBean指定配制获取容器JNDI资源的FactoryBean! 老的用法 <bean id="simple" class="org.springframework.jndi.JndiObjectFactoryBean"> <property name="jndiName" value="jdbc/MyDataSource"/> <property name="cache" value="true"/> <property name="resourceRef" value="true"/> <property name="lookupOnStartup" value="false"/> <property name="expectedType" value="com.myapp.DefaultFoo"/> <property name="proxyInterface" value="com.myapp.Foo"/> </bean> 新用法 <jee:jndi-lookup id="simple" jndi-name="jdbc/MyDataSource" cache="true" resource-ref="true" lookup-on-startup="false" expected-type="com.myapp.DefaultFoo" proxy-interface="com.myapp.Foo"/> 8,<jee:local-slsb/> 替代了之前使用LocalStatelessSessionProxyFactoryBean来获取无状态会话BEAN的FactoryBean! 老的用法 <bean id="complexRemoteEjb" class="org.springframework.ejb.access.LocalStatelessSessionProxyFactoryBean"> <property name="jndiName" value="ejb/MyRemoteBean"/> <property name="businessInterface" value="com.foo.service.RentalService"/> <property name="cacheHome" value="true"/> <property name="lookupHomeOnStartup" value="true"/> <property name="resourceRef" value="true"/> <property name="homeInterface" value="com.foo.service.RentalService"/> <property name="refreshHomeOnConnectFailure" value="true"/> </bean> 新的用法 <jee:remote-slsb id="complexRemoteEjb" jndi-name="ejb/MyRemoteBean" business-interface="com.foo.service.RentalService" cache-home="true" lookup-home-on-startup="true" resource-ref="true" homeinterface="com.foo.service.RentalService" refresh-home-on-connect-failure="true"> </span>