List –
Set –
Map –
Properties –
Spring beans
一个Customer对象,有四个集合属性。
package com.yiibai.common;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
public class Customer
{
private List lists;
private Set sets;
private Map maps;
private Properties pros;
//...
}
在bean配置文件中不同的代码片段用来声明集合。
1. List示例
1
2. Set示例
1
3. Map示例
4. Properties示例
admin@yiibai.com
support@yiibai.com
Spring完整的 bean 配置文件。
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-2.5.xsd">
1
1
admin@yiibai.com
support@yiibai.com
执行程序
package com.yiibai.common;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class App
{
public static void main( String[] args )
{
ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
Customer cust = (Customer)context.getBean("CustomerBean");
System.out.println(cust);
}
}
输出