Java 在春季注入arraylist时出现问题
我使用的是spring 3.2.2。在spring中使用util:list标记注入集合(ArrayList)时,我遇到了一个问题Java 在春季注入arraylist时出现问题,java,spring,Java,Spring,我使用的是spring 3.2.2。在spring中使用util:list标记注入集合(ArrayList)时,我遇到了一个问题 package com.springaction.testmultidimesionalcollection; import java.util.List; /** * @author jinesh * */ public class Address { List<Country> country; public List
package com.springaction.testmultidimesionalcollection;
import java.util.List;
/**
* @author jinesh
*
*/
public class Address {
List<Country> country;
public List<Country> getCountry() {
return country;
}
/**
* @param country the country to set
*/
public void setCountry(List<Country> country) {
this.country = country;
}
}
但是当它尝试加载spring配置文件时,我得到了下面的异常
Caused by: org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'java.util.ArrayList' to required type 'java.util.List' for property 'country'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.util.ArrayList] to required type [com.springaction.testmultidimesionalcollection.Country] for property 'country[0]': no matching editors or conversion strategy found
at org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:463)
at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:494)
at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:488)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1439)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1398)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1134)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:522)
... 11 more
Caused by: java.lang.IllegalStateException: Cannot convert value of type [java.util.ArrayList] to required type [com.springaction.testmultidimesionalcollection.Country] for property 'country[0]': no matching editors or conversion strategy found
at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:264)
at org.springframework.beans.TypeConverterDelegate.convertToTypedCollection(TypeConverterDelegate.java:559)
at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:199)
at org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:448)
... 17 more
我不明白为什么春天会有这样的例外?我在spring配置中遗漏了什么吗?不是这个
<util:list list-class="java.util.ArrayList"
删除
标记:
<util:list list-class="java.util.ArrayList" value-type="com.springaction.testmultidimesionalcollection.Country">
<list>
<ref bean="countryChina"/>
<ref bean="countryIndia"/>
<ref bean="countryAus"/>
</list>
</util:list>
到
我想
在@whoAmI下面,谢谢你指出了一个愚蠢的错误。它确实解决了这个问题。
<util:list list-class="java.util.ArrayList"
<util:list list-class="java.util.List"
<util:list list-class="java.util.ArrayList" value-type="com.springaction.testmultidimesionalcollection.Country">
<list>
<ref bean="countryChina"/>
<ref bean="countryIndia"/>
<ref bean="countryAus"/>
</list>
</util:list>
<util:list list-class="java.util.ArrayList" value-type="com.springaction.testmultidimesionalcollection.Country">
<ref bean="countryChina"/>
<ref bean="countryIndia"/>
<ref bean="countryAus"/>
</util:list>