Person.java
Public class Person { private Long pid; Private String pname; Private Student Student; Private list List; Private set set; Private map map; Private Properties Properties; // get and Set methods }
Applicationcontext.xml
1 <?XML version= "1.0" encoding= "UTF-8"?>2 <Beansxmlns= "Http://www.springframework.org/schema/beans"3 Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"4 xsi:schemalocation= "Http://www.springframework.org/schema/beans5 http://www.springframework.org/schema/beans/spring-beans-2.5.xsd ">6 7 <Beanname= "Person"class= "Cn.test.di.Person">8 <!-- 9 property is the representation attributeTen in spring, the base type (wrapper type and string) can be assigned with value One reference types are assigned with ref values A - - < Propertyname= "pid"value= "5"></ Property> - < Propertyname= "PName"value= "Zhang San"></ Property><!--Basic data Types - the < Propertyname= "Student"ref= "Student"></ Property><!--Reference type - - < Propertyname= "List"> - <List> - <value>List1</value> + <value>List2</value> - <refBean= "Student"/> + </List> A </ Property> at - < Propertyname= "Set"> - <Set> - <value>Set1</value> - <value>Set2</value> - <refBean= "Student"/> in </Set> - </ Property> to < Propertyname= "Map"> + <Map> - <entryKey= "Map1"> the <value>Map1</value> * </entry> $ <entryKey= "Map2">Panax Notoginseng <value>Map2</value> - </entry> the <entryKey= "MAP3"> + <refBean= "Student"/> A </entry> the </Map> + </ Property> - < Propertyname= "Properties"> $ <Props> $ <propKey= "Pro1"> - Pro1 - </prop> the </Props> - </ Property>Wuyi </Bean> the <Beanname= "Student"class= "Cn.test.di.Student"></Bean> - </Beans>
Test
1 @Test2 Public voidDosome () {3ApplicationContext applicationcontext=NewClasspathxmlapplicationcontext ("Cn/test/di/applicationcontext.xml");4Person person= (person) applicationcontext.getbean (' person ');5 System.err.println (Person.getpid ());6 System.err.println (Person.getpname ());7 person.getstudent (). Say ();8List list=person.getlist ();9 for(intI=0;i<list.size (); i++){Ten System.err.println (List.get (i). toString ()); One}
Spring_di using Set method to assign a value to Demo