pom.xml
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.3.14.RELEASE</version>
</dependency>
package com.spring.lessonTest.collection;
import java.util.List;
import java.util.Map;
import java.util.Properties;
/**
* @InterfaceName:ICollection 用途:
* 作者: litaofeng
* 时间: 2019/6/27 13:34
*/
public interface ICollection {
List<Object> getList();
Map<String, Object> getMap();
Properties getPros();
}
package com.spring.lessonTest.collection;
import java.util.List;
import java.util.Map;
import java.util.Properties;
/**
* @ClassName:CollectionImpl
* @Description:
* @author: Torey
*/
public class CollectionImpl implements ICollection {
private List<Object> list;
private Map<String,Object> map;
private Properties pros;
@Override
public List<Object> getList() {
return list;
}
public void setList(List<Object> list) {
this.list = list;
}
@Override
public Map<String, Object> getMap() {
return map;
}
public void setMap(Map<String, Object> map) {
this.map = map;
}
@Override
public Properties getPros() {
return pros;
}
public void setPros(Properties pros) {
this.pros = pros;
}
}
springApplicationContext.xml
package com.spring.lessonTest.collection;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import java.util.List;
import java.util.Map;
import java.util.Properties;
/**
* @ClassName:TestCollection
* @Description:
* @author: Torey
*/
public class TestCollections {
public static void main(String[] args){
ApplicationContext context = new ClassPathXmlApplicationContext("springApplicationContext.xml");
ICollection con=(ICollection) context.getBean("collectionTest");
List<Object> list = con.getList();
System.out.println(list);
Map<String, Object> map = con.getMap();
System.out.println(map);
Properties pros = con.getPros();
System.out.println(pros);
}
}
<?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">
<bean name="collectionTest" class="com.spring.lessonTest.collection.CollectionImpl">
<property name="list">
<list>
<value>AAA-1</value>
<value>AAA-2</value>
</list>
</property>
<property name="map">
<map>
<entry key="key-1" value="value-1"/>
<entry key="key-2" value="value-2"/>
</map>
</property>
<property name="pros">
<props>
<prop key="pro-1">pro_value1</prop>
<prop key="pro-2">pro_value2</prop>
</props>
</property>
</bean>
</beans>