0
votes
 import java.awt.List;
   import java.util.Properties;

   public class CollectionExample {

    private List examplelist;

    private Properties exampleprop;

    public List getExamplelist() {
        System.out.println("List Element : " + examplelist);
        return examplelist;
    }

    public void setExamplelist(List examplelist) {
        examplelist = examplelist;
    }

    public Properties getExampleprop() {
        System.out.println("List Element : " + exampleprop);
        return exampleprop;
    }

    public void setExampleprop(Properties exampleprop) {
        this.exampleprop = exampleprop;
    }

}

And my main class is :

    public class CollectionExample {

    private List examplelist;

    private Properties exampleprop;

    public List getExamplelist() {
        System.out.println("List Element : " + examplelist);
        return examplelist;
    }

    public void setExamplelist(List examplelist) {
        examplelist = examplelist;
    }

    public Properties getExampleprop() {
        System.out.println("List Element : " + exampleprop);
        return exampleprop;
    }

    public void setExampleprop(Properties exampleprop) {
        this.exampleprop = exampleprop;
}

}



My .xml file is :
<bean id = "collectionExample"  class = "com.demo.spring.beans.CollectionExample" >
  <property name="examplelist">
    <list>
           <value>Credit Card</value>
           <value>COD</value>
           <value>Check</value>
           <value>Cash</value>
    </list>
  </property>
  <property name="exampleprop">
    <props>
        <prop key="one">Server Name</prop>
         <prop key="one">User Name</prop>
          <prop key="one">Password</prop>
           <prop key="one">Secure Token</prop>
    </props>
  </property>

</bean>

There is a exception : Jun 04, 2015 5:56:22 PM org.springframework.context.support.ClassPathXmlApplicationContext prepareRefresh INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@2d8e6db6: startup date [Thu Jun 04 17:56:22 IRDT 2015]; root of context hierarchy Jun 04, 2015 5:56:22 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions INFO: Loading XML bean definitions from class path resource [NewFile.xml] Jun 04, 2015 5:56:22 PM org.springframework.context.support.ClassPathXmlApplicationContext refresh WARNING: Exception encountered during context initialization - cancelling refresh attempt org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'collectionExample' defined in class path resource [NewFile.xml]: Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'java.util.ArrayList' to required type 'java.awt.List' for property 'examplelist'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.util.ArrayList] to required type [java.awt.List] for property 'examplelist': no matching editors or conversion strategy found at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:547) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:755) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480) at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:139) at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:83) at com.demo.spring.beans.CollectionExampleApp.main(CollectionExampleApp.java:9) Caused by: org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'java.util.ArrayList' to required type 'java.awt.List' for property 'examplelist'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.util.ArrayList] to required type [java.awt.List] for property 'examplelist': no matching editors or conversion strategy found at org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:476) at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:512) at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:506) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1523) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1482) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1222) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537) ... 11 more Caused by: java.lang.IllegalStateException: Cannot convert value of type [java.util.ArrayList] to required type [java.awt.List] for property 'examplelist': no matching editors or conversion strategy found at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:287) at org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:461) ... 17 more

Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'collectionExample' defined in class path resource [NewFile.xml]: Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'java.util.ArrayList' to required type 'java.awt.List' for property 'examplelist'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.util.ArrayList] to required type [java.awt.List] for property 'examplelist': no matching editors or conversion strategy found at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:547) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:755) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480) at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:139) at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:83) at com.demo.spring.beans.CollectionExampleApp.main(CollectionExampleApp.java:9) Caused by: org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'java.util.ArrayList' to required type 'java.awt.List' for property 'examplelist'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.util.ArrayList] to required type [java.awt.List] for property 'examplelist': no matching editors or conversion strategy found at org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:476) at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:512) at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:506) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1523) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1482) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1222) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537) ... 11 more Caused by: java.lang.IllegalStateException: Cannot convert value of type [java.util.ArrayList] to required type [java.awt.List] for property 'examplelist': no matching editors or conversion strategy found at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:287) at org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:461) ... 17 more

2
What do you think this Failed to convert property value of type 'java.util.ArrayList' to required type 'java.awt.List' for property 'examplelist' means?Sotirios Delimanolis

2 Answers

2
votes

Look closely at this part of the error message:

Cannot convert value of type [java.util.ArrayList] to required type [java.awt.List] for property 'examplelist'

You have imported the wrong List in your code. Change this:

import java.awt.List;

to this:

import java.util.List;
1
votes

Please change import java.awt.List to import java.util.List.

The java.awt.List class is used for GUI purposes.