Spring配置中使用util标签

         需要在applicationContext.xml文件中的开头部分加入以下描述:xmlns:util=" http://www.springframework.org/schema/util ",并在xsi:schemaLocation描述中插入以下xsd描述:
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd

示例:

bean:

package com.yourcompany.spring;

import java.util.List;
import java.util.Map;
import java.util.Set;

public class SomeBean{	
	
    private List list;
    private Map map;
    private Set set;
    
	public List getList() {
		return list;
	}
	public void setList(List list) {
		this.list = list;
	}
	public Map getMap() {
		return map;
	}
	public void setMap(Map map) {
		this.map = map;
	}
	public Set getSet() {
		return set;
	}
	public void setSet(Set set) {
		this.set = set;
	}
}

applicationContext.xml




	
        
        
        
    
    
	    listValue1
	    listValue2
    
    
	    
	    	mapValue1
	    
	    
	    	mapValue2
	    
    
    
	    setValue1
	    setValue2
    

程序主入口:

package com.yourcompany.spring;

import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;


public class User{
    public static void main(String[] args){
	    ApplicationContext context=new ClassPathXmlApplicationContext("applicationContext.xml");
	    SomeBean someBean=(SomeBean)context.getBean("someBean");
	    List list = someBean.getList();
	    Map map = someBean.getMap();
	    Set set = someBean.getSet();
	    for(int i=0;i

你可能感兴趣的:(spring,util标签,util命名空间,Java,J2SE,J2EE,框架,Spring)