Spring: XML Schema-based configuration (ii)

Source: Internet
Author: User

[This tutorial is translated from the official spring document and is properly deleted]

Continuation of the previous article:


<util:list/>

If you were to assemble a collection (List), you would write this:

<!--creates a Java.util.List instance with values loaded from the supplied sourceList--><bean id= "emails" class = "Org.springframework.beans.factory.config.ListFactoryBean" >    <property name= "SourceList" >        < list>            <value>[email protected]</value>            <value>[email protected]</value>            <value>[email protected]</value>            <value>[email protected]</value>        </list>    </property></bean>

Now you can:

<!--creates a java.util.List instance with the supplied values--><util:list id= "emails" >    <value> [Email protected]</value>    <value>[email protected]</value>    <value>[email protected]</value>    <value>[email protected]</value></util:list>

You can also customize the implementation of the list, such as <util:list id= "emails" list-class= "java.util.LinkedList" >

(The ID is set to reuse the collection)

The usage of Map,set is similar here not to introduce.


It is necessary to note that both,<list> and <set> can assemble any implementation or array of java.util.Collection.

referencing other beans,

<list>   <ref bean= "..."/><list>

Members of the list also include:<value><bean><null/>

For map,

<map>    <entry key= "GUITAR" value= "..."/>    <entry key= "cymbal" ref-value= "..."/></map >


    • Jee Mode
JEE tags are designed to handle Java EE-related configurations, such as querying Jndi objects and defining references to EJBS. of course, you have to add a namespace before using it.
<?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:jee= "Http://www.springframework.org/schema/jee "Xsi:schemalocation="        Http://www.springframework.org/schema/beans http://www.springframework.org/schema/ Beans/spring-beans.xsd        Http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/ Spring-jee.xsd "> <!--bean definitions here--></beans>

The following example is a data source defined using Jndi,before you write this:
<bean id= "DataSource" class= "Org.springframework.jndi.JndiObjectFactoryBean" >    <property name= " Jndiname "value=" Jdbc/mydatasource "/></bean><bean id=" Userdao "class=" Com.foo.JdbcUserDao ">    <!--Spring would do the cast automatically (as usual)-    <property name= "DataSource" ref= "DataSource"/>& Lt;/bean>

Now, you can:
<jee:jndi-lookup id= "DataSource" jndi-name= "Jdbc/mydatasource"/><bean id= "Userdao" class= " Com.foo.JdbcUserDao >    <!--Spring would do the cast automatically (as usual)-    <property name= " DataSource "ref=" DataSource "/></bean>

The following is a more complex configuration:
<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"/>



Spring: XML Schema-based configuration (ii)

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.