官方文档

https://docs.spring.io/spring-framework/docs/current/reference/html/core.html#beans-collection-elements

Student POJO类

package com.DI.pojo;

import lombok.Data;
import java.util.*;

@Data
public class Student {
private String name;
private Address address;
private String[] books;
private List<String> hobbys;
private Map<String, String> card;
private Set<String> games;
private String wife;
private Properties info;
public void test() {
System.out.println("我是Student");
}
}

Address POJO类

package com.DI.pojo;

import lombok.Data;

@Data
public class Address {
private String address;
public void test() {
System.out.println("我是Address");
}
}

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"
xsi:schemaLocation="http://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans.xsd">

<bean id="Address" class="com.DI.pojo.Address">
<property name="address" value="xiamen"></property>
</bean>
<bean id="Student" class="com.DI.pojo.Student">
<!--bean注入-->
<property name="address" ref="Address"></property>
<!--普通值注入-->
<property name="name" value="chenxb"></property>
<!--数组注入-->
<property name="books">
<array>
<value>语文</value>
<value>数学</value>
<value>英语</value>
</array>
</property>
<property name="hobbys">
<list>
<value>看书</value>
<value>打球</value>
</list>
</property>
<property name="card">
<map>
<entry key="学生卡" value="1111111"></entry>
<entry key="身份证" value="2222222"></entry>
</map>
</property>
<property name="games">
<set>
<value>唱歌</value>
<value>跳舞</value>
</set>
</property>
<property name="wife">
<null></null>
</property>
<property name="info">
<props>
<prop key="学号">666</prop>
<prop key="姓名">小明</prop>
</props>
</property>
</bean>
</beans>

测试类

package com.DI;

import com.DI.pojo.Student;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class TestDI {
@Test
public void test() {
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("DI.xml");
Student student=applicationContext.getBean(Student.class);
student.test();
student.getAddress().test();
System.out.println(student);
}
}