package com.h3.common; import java.util.list; public class customer { private list lists; //... }
<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-2.5.xsd"> <bean id="customerbean" class="com.h3.common.customer"> <property name="lists"> <bean class="org.springframework.beans.factory.config.listfactorybean"> <property name="targetlistclass"> <value>java.util.arraylist</value> </property> <property name="sourcelist"> <list> <value>one</value> <value>2</value> <value>three</value> </list> </property> </bean> </property> </bean> </beans>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:util="http://www.springframework.org/schema/util" xsi:schemalocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd"> <bean id="customerbean" class="com.h3.common.customer"> <property name="lists"> <util:list list-class="java.util.arraylist"> <value>one</value> <value>2</value> <value>three</value> </util:list> </property> </bean> </beans>
caused by: org.xml.sax.saxparseexception: the prefix "util" for element "util:list" is not bound.
执行,查看结果:
package com.h3.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); } }
输出结果
customer [lists=[one, 2, three]] type=[class java.util.arraylist]