ioc.xml
<?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:p="http://www.springframework.org/schema/p" xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/util https://www.springframework.org/schema/util/spring-util.xsd">
<bean id="person1" class="com.kerwin.bean.Person">
<property name="id" value="6"></property>
<property name="name" value="zhangsan6"></property>
<property name="age" value="26"></property>
<property name="gender" value="男6"></property>
<!--<property name="hobbies" value="book,girl,movie"></property>-->
<property name="hobbies">
<array>
<value>book</value>
<value>girl</value>
<value>movie</value>
</array>
</property>
<property name="address" ref="address"></property>
<!--<property name="lists" value="1,2,3"></property>-->
<property name="lists">
<list>
<bean id="address2" class="com.kerwin.bean.Address">
<property name="province" value="北京"></property>
<property name="city" value="1"></property>
</bean>
<bean class="com.kerwin.bean.Address">
<property name="province" value="上海"></property>
<property name="city" value="2"></property>
</bean>
<ref bean="address"></ref>
</list>
</property>
<property name="sets">
<set>
<value>zhangsan</value>
<value>zhangsan</value>
<value>lisi</value>
</set>
</property>
<property name="maps">
<map>
<entry key="a" value="aaa"></entry>
<entry key="address" value-ref="address"></entry>
<entry key="address2">
<bean class="com.kerwin.bean.Address">
<property name="province" value="广东省"></property>
</bean>
</entry>
<entry>
<key>
<value>heihei</value>
</key>
<value>haha</value>
</entry>
<entry key="list">
<list>
<value>11</value>
<value>22</value>
</list>
</entry>
</map>
</property>
<property name="properties">
<props>
<prop key="111">aaa</prop>
<prop key="222">bbb</prop>
</props>
</property>
</bean>
<bean id="address" class="com.kerwin.bean.Address" depends-on="person"></bean>
<bean id="person" class="com.kerwin.bean.Person"></bean>
</beans>
public class Person {
private int id;
private String name;
private Integer age;
private String gender;
private String[] hobbies;
private Address address;
private List<Address> lists;
private Set<String> sets;
private Map<String, Object> maps;
private Properties properties;
}
public class Address {
private String province;
private String city;
private String town;
}
ApplicationContext context = new ClassPathXmlApplicationContext("ioc.xml");
Person person = context.getBean("person1", Person.class);
System.out.println(person6);