Spring Util namespaces

Source: Internet
Author: User

The Util namespace in spring's configuration file is similar to the Java.util package class, and the Util namespace provides a collection-related configuration to import the Util namespace before using the namespace, as follows:

    • Util namespace Introduction
1 <  xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"2    xmlns:util  = "Http://www.springframework.org/schema/util"3    xsi:schemalocation = "Http://www.springframework.org/schema/util http://www.springframework.org/schema/util/ Spring-util-4.1.xsd ">
    • Configuring a list in spring
1 <!--Configure a list collection with the Util namespace--
2 <util:listID= "UserList"Value-type= "Java.lang.String">4 <value>Tom</value>5 <value>John doe</value>6 <value>Harry</value>7 </util:list>
    • Configuring a Map collection in spring
1 <!--Configuring a Map collection -2     <Util:mapID= "UserMap">3         <entryKey= "User1"Value-ref= "User" />4         <entryKey= "User2">5             <!--Configuring an internal bean -6             <Beanclass= "Io.shuqi.ssh.spring.util.User">7                 < Propertyname= "Userage"value= " a" />8                 < Propertyname= "UserName"value= "Xiao Zhang" />9             </Bean>Ten         </entry> One     </Util:map>
    • Configuring a set set in spring
1 <!--util Configuring a set Set -2     <Util:setID= "Userset">3         <value>Tom</value>4         <value>Harry</value>5         <value>Zhao Liu</value>6     </Util:set>

    • Configuring a Properties collection in spring
<!--Configure a Properties -<util:propertiesID= "UserProperties">        <propKey= "Name">Tom</prop>        <propKey= "Age">12</prop></util:properties><!--A properties file to configure a properties -<util:properties Location= "Classpath:io/shuqi/ssh/spring/util/jdbc.properties"ID= "JDBC" />

In fact, <util:list>, <util:map>, <util:set>, <util:properties> and other tags are used by spring to A simple notation to replace Listfactorybean, Mapfactorybean, Setfactorybean, Propertiesfactorybean

    • Other ways to load the configuration file properties in spring
1     <!-- 2 Context:property-placeholder (propertysourcesplaceholderconfigurer)3 load a Properties profile, and you can use the ${key} expression elsewhere to occupy the value of a bit property,4 *spring 2.5 can register the bean (Org.springframework.context.support.PropertySourcesPlaceholderConfigurer) before loading the configuration file 5      -6     <!--Spring 2.5 Used to load configuration files by registering beans -7     <Beanclass= "Org.springframework.context.support.PropertySourcesPlaceholderConfigurer"p:location= "Classpath:io/shuqi/ssh/spring/util/jdbc.properties"></Bean>8     <!--Loading properties files using the context namespace -9     <Context:property-placeholder Location= "Classpath:io/shuqi/ssh/spring/util/jdbc.properties" />

Spring Util namespaces

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.