<?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
http://www.springframework.org/schema/beans/spring-beans.xsd">
<!-- 配置Service -->
<bean id="customerService" class="com.itheima.service.impl.CustomerServiceImpl">
<!-- 注入DAO的属性 -->
<property name="customerDao" ref="customerDao"/>
</bean>
<!-- 配置DAO -->
<bean id="customerDao" class="com.itheima.dao.impl.CustomerDaoImpl">
</bean>
</beans>
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* @author lw
* @createTime 2018/10/12 10:28
* @description 集合属性的注入:
*/
public class CollectionBean {
private String[] arrs;
private List<String> list;
private Set<String> set;
private Map<String,String> map;
public void setArrs(String[] arrs) {
this.arrs = arrs;
}
public void setList(List<String> list) {
this.list = list;
}
public void setSet(Set<String> set) {
this.set = set;
}
public void setMap(Map<String, String> map) {
this.map = map;
}
@Override
public String toString() {
return "CollectionBean [arrs=" + Arrays.toString(arrs) + ", list=" + list + ", set=" + set + ", map=" + map
+ "]";
}
}
import com.pojo.CollectionBean;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
* @author lw
* @createTime 2018/10/12 10:20
* @description 集合
*/
public class SprintDome {
@Test
public void demo1() {
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("com/pojo/applicationContexolad.xml");
CollectionBean collectionBean = (CollectionBean) applicationContext.getBean("collectionBean");
System.out.println(collectionBean);
}
}
原文:http://blog.51cto.com/357712148/2299138