gpt4 book ai didi

Java-如何修复 Spring 框架中的异常?

转载 作者:行者123 更新时间:2023-12-01 22:17:45 25 4
gpt4 key购买 nike

 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;
}

}

我的主要类(class)是:

    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

最佳答案

仔细查看错误消息的这一部分:

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

您在代码中导入了错误的List。更改此:

import java.awt.List;

对此:

import java.util.List;

关于Java-如何修复 Spring 框架中的异常?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30647126/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com