Spring util namespace and util namespace

Source: Internet
Author: User

Spring util namespace and util namespace

In the spring configuration file, the util namespace is similar to the java. util package class. The util namespace provides collection-related configurations. before using the namespace, import the util namespace, as shown below:

  • Util namespace Introduction
1 <beans 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">
  • Configure a List in spring
1 <! -- Use the util namespace to configure a List set -->
2 <util: list id = "userList" value-type = "java. lang. string "> 4 <value> Zhang San </value> 5 <value> Li Si </value> 6 <value> Wang Wu </value> 7 </util: list>
  • Configure a Map set in spring
1 <! -- Configure a Map set --> 2 <util: map id = "userMap"> 3 <entry key = "user1" value-ref = "user"/> 4 <entry key = "user2"> 5 <! -- Configure an internal Bean --> 6 <bean class = "io. shuqi. ssh. spring. util. user "> 7 <property name =" userAge "value =" 12 "/> 8 <property name =" userName "value =" John "/> 9 </bean> 10 </entry> 11 </util: map>
  • Configure a Set in spring
1 <! -- Util configure a Set --> 2 <util: set id = "userSet"> 3 <value> Item 3 </value> 4 <value> Item 5 <value> Item 6 </value> 6 </util: set>

 

  • Configure a Properties set in spring
<! -- Configure a Properties --> <util: properties id = "userProperties"> <prop key = "name"> JOHN </prop> <prop key = "age"> 12 </prop> </util: properties> <! -- Use a properties file to configure a properties --> <util: properties location = "classpath: io/shuqi/ssh/spring/util/jdbc. properties "id =" jdbc "/>

 

In fact, labels such as <util: list>, <util: map>, <util: set>, and <util: properties> are simple methods for spring to replace ListFactoryBean, MapFactoryBean, SetFactoryBean, and PropertiesFactoryBean.

  • Other methods for loading configuration file Properties in spring
1 <! -- 2 context: property-placeholder (PropertySourcesPlaceholderConfigurer) 3. Load a properties configuration file and use the $ {key} expression elsewhere to hold the attribute value, 4 * bean (org. springframework. context. support. propertySourcesPlaceholderConfigurer) to load the configuration file 5 --> 6 <! -- The configuration file is loaded by bean registration before spring 2.5 --> 7 <bean class = "org. springframework. context. support. propertySourcesPlaceholderConfigurer "p: location =" classpath: io/shuqi/ssh/spring/util/jdbc. properties "> </bean> 8 <! -- Use the context namespace to load the Properties file --> 9 <context: property-placeholder location = "classpath: io/shuqi/ssh/spring/util/jdbc. properties"/>

 

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.