[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 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)