CollectionBean类
package com.xqw.pojo; import java.util.*; public class CollectionBean { private List<String> lists; private Integer[] arrs; private Set<String> sets; private Map<String, String> maps; private Properties properties; public List<String> getLists() { return lists; } public void setLists(List<String> lists) { this.lists = lists; } public Integer[] getArrs() { return arrs; } public void setArrs(Integer[] arrs) { this.arrs = arrs; } public Set<String> getSets() { return sets; } public void setSets(Set<String> sets) { this.sets = sets; } public Map<String, String> getMaps() { return maps; } public void setMaps(Map<String, String> maps) { this.maps = maps; } public Properties getProperties() { return properties; } public void setProperties(Properties properties) { this.properties = properties; } @Override public String toString() { return "CollectionBean{" + "lists=" + lists + ", arrs=" + Arrays.toString(arrs) + ", sets=" + sets + ", maps=" + maps + ", properties=" + properties + '}'; } } 配置文件中
<?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 id="collectionBean" class="com.xqw.pojo.CollectionBean"> <property name="lists"> <list> <value>1</value> <value>2</value> </list> </property> <property name="arrs"> <array> <value>1</value> <value>2</value> </array> </property> <property name="sets"> <set> <value>1</value> <value>1</value> </set> </property> <property name="maps"> <map> <entry key="1" value="haha"/> <entry key="2" value="heihei"/> </map> </property> <property name="properties"> <props> <prop key="1">haha</prop> <prop key="2">heihei</prop> </props> </property> </bean> </beans>
测试类
import com.xqw.pojo.CollectionBean; import org.springframework.beans.factory.BeanFactory; import org.springframework.context.support.ClassPathXmlApplicationContext; public class CollectionBeanTest { public static void main(String[] args) { BeanFactory beanFactory=new ClassPathXmlApplicationContext("bean2.xml"); CollectionBean collectionBean= (CollectionBean) beanFactory.getBean("collectionBean"); System.out.println(collectionBean ); } } 测试结果标签:map,set,list,lists,properties,maps,arrs,sets,public From: https://blog.csdn.net/m0_73903724/article/details/144140281