A Test bean:
Package util;
public class Testbean {Private Integer Co;Public Integer Getco () {
return CO;
}
public void Setco (Integer co) {
this.co = CO;
}
}
Configuration file:
<?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:util= "http://www.springframework.org/schema/util"
Xsi:schemalocation= "Http://www.springframework.org/schema/beans&NBSP;
http:// Www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/util
< Span style= "Background-color: #ff0000;" >http://www.springframework.org/schema/util/spring-util-2.0.xsd "
<bean id= "test" class= "util. Test ">
<property name= "list" ref= "List" >
</property>
<property name= "map" ref= "map" >
</property>
<property name= "Properties" ref= "Properties" >
</property>
<property name= "Array" ref= "Array" >
</property>
<property name= "Set" ref= "Set" >
</property>
<property name= "Constantvalue" ref= "Constantvalue" >
</property>
</bean>
<util:list id= "list" list-class= "Java.util.ArrayList" >
<value>listValue1</value>
<value>listValue2</value>
</util:list>
<util:map id= "Map" >
<entry key= "Key1" value= "mapValue1" ></entry>
<entry key= "Key12" value= "MapValue2" ></entry>
</util:map>
<util:set id= "Set" set-class= "Java.util.TreeSet" >
<value>setValue1</value>
<value>setValue2</value>
</util:set>
<util:properties id= "Properties" location= "Classpath:/util/config.properties" >
</util:properties>
<util:list id= "Array" >
<value>arrayValue1</value>
<value>arrayValue2</value>
</util:list>
<!--Define Constants--
<util:constant id= "Constantvalue" static-field= "Java.sql.Connection.TRANSACTION_SERIALIZABLE"/>
<!--defines the ID for the Bean attribute member for reference by other beans, but its own properties are not available and can only be used on other beans--
<util:property-path id= "source" path= "Test.constantvalue"/>
<bean id= "Testbean" class= "util. Testbean ">
<property name= "CO" >
<ref bean= "source"/>
</property>
</bean>
</beans>
Test procedure:
Package util;
Import java.util.Enumeration;
Import Java.util.Iterator;
Import java.util.List;
Import Java.util.Map;
Import java.util.Properties;
Import Java.util.Set;
Import Org.springframework.context.ApplicationContext;
Import Org.springframework.context.support.ClassPathXmlApplicationContext;
public class Test {
Private list List;
private map map;
Private string[] array;
Private set set;
private properties Properties;
Private Integer Constantvalue;
Public Integer Getconstantvalue () {
return constantvalue;
}
public void Setconstantvalue (Integer constantvalue) {
This.constantvalue = Constantvalue;
}
Public List getList () {
return list;
}
public void setlist (list list) {
This.list = list;
}
Public Map Getmap () {
return map;
}
public void Setmap (map map) {
This.map = map;
}
Public string[] GetArray () {
return array;
}
public void SetArray (string[] array) {
This.array = array;
}
Public Set Getset () {
return set;
}
public void Setset (set set) {
This.set = set;
}
Public Properties getProperties () {
return properties;
}
public void SetProperties (properties properties) {
This.properties = properties;
}
public static void Main (string[] args) {
ApplicationContext ctx=new classpathxmlapplicationcontext ("Util/applicationcontext.xml");
Test t= (Test) Ctx.getbean ("test");
T.printarray (T.getarray ());
T.printlist (T.getlist ());
T.printmap (T.getmap ());
T.printset (T.getset ());
T.printproperties (T.getproperties ());
System.out.println (T.getconstantvalue ());
Testbean tb= (Testbean) Ctx.getbean ("Testbean");
System.out.println ("Use Util:property-path:" +tb.getco ());
}
public void printlist (List result) {
SYSTEM.OUT.PRINTLN ("List value:");
for (Iterator Iterator = Result.iterator (); Iterator.hasnext ();) {
string element = (string) iterator.next ();
SYSTEM.OUT.PRINTLN (Element);
}
}
public void Printmap (Map result) {
SYSTEM.OUT.PRINTLN ("Map value:");
for (Iterator Iterator = Result.keyset (). Iterator (); Iterator.hasnext ();) {
string element = (string) iterator.next ();
SYSTEM.OUT.PRINTLN (Element);
}
}
public void Printset (Set result) {
System.out.println ("Set Value:");
for (Iterator Iterator = Result.iterator (); Iterator.hasnext ();) {
string element = (string) iterator.next ();
SYSTEM.OUT.PRINTLN (Element);
}
}
public void PrintArray (string[] result) {
SYSTEM.OUT.PRINTLN ("Array value:");
for (int i = 0; i < result.length; i++) {
System.out.println (Result[i]);
}
}
public void printproperties (Properties result) {
System.out.println ("Properties Value:");
Enumeration Enu2=result.propertynames ();
while (Enu2.hasmoreelements ()) {
String key = (string) enu2.nextelement ();
SYSTEM.OUT.PRINTLN (key);
}
}
}
Test results:
Array value:
ArrayValue1
ArrayValue2
List value:
ListValue1
ListValue2
Map value:
Key1
Key12
Set Value:
SetValue1
SetValue2
Properties Value:
Prop2
Prop1
8
Use Util:property-path:8
New tags for Spring 2.0----Util instances