我遇到了下面给出的错误:
堆栈跟踪
Apr 16,2014 12:21:23 PM org.springframework.beans.factory.xml.XmlBeanDeFinitionReader loadBeanDeFinitions
INFO: Loading XML bean deFinitions from class path resource [beans.xml]
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'collectionsWithProps' defined in class path resource [beans.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'adminemails' of bean class [com.student.spring.impl.CollectionsWithProps]: Bean property 'adminemails' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
at org.springframework.beans.factory.support.AbstractAutowireCapablebeanfactory.applyPropertyValues(AbstractAutowireCapablebeanfactory.java:1396)
at org.springframework.beans.factory.support.AbstractAutowireCapablebeanfactory.populateBean(AbstractAutowireCapablebeanfactory.java:1118)
at org.springframework.beans.factory.support.AbstractAutowireCapablebeanfactory.doCreateBean(AbstractAutowireCapablebeanfactory.java:517)
at org.springframework.beans.factory.support.AbstractAutowireCapablebeanfactory.createBean(AbstractAutowireCapablebeanfactory.java:456)
at org.springframework.beans.factory.support.Abstractbeanfactory$1.getobject(Abstractbeanfactory.java:294)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
at org.springframework.beans.factory.support.Abstractbeanfactory.doGetBean(Abstractbeanfactory.java:291)
at org.springframework.beans.factory.support.Abstractbeanfactory.getBean(Abstractbeanfactory.java:193)
at com.student.spring.test.MyTest.main(MyTest.java:26)
Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'adminemails' of bean class [com.student.spring.impl.CollectionsWithProps]: Bean property 'adminemails' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:1064)
at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:924)
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:76)
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:58)
at org.springframework.beans.factory.support.AbstractAutowireCapablebeanfactory.applyPropertyValues(AbstractAutowireCapablebeanfactory.java:1393)
... 8 more
这是我的MyTest.java
package com.student.spring.test;
import java.util.Properties;
import org.springframework.beans.factory.beanfactory;
import org.springframework.beans.factory.xml.Xmlbeanfactory;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import com.student.spring.impl.CollectionsWithProps;
@SuppressWarnings("deprecation")
public class MyTest {
public static void main(String[] args) {
Resource resource = new ClassPathResource("beans.xml");
beanfactory beanfactory = new Xmlbeanfactory(resource);
CollectionsWithProps cwp = (CollectionsWithProps) beanfactory
.getBean("collectionsWithProps");
System.out.println(cwp);
}
}
这是CollectionsWithProps.java
package com.student.spring.impl;
import java.util.Properties;
public class CollectionsWithProps {
private Properties emails=null;
public Properties getEmails() {
return emails;
}
public void setEmails(Properties emails) {
this.emails = emails;
}
public String toString(){
return "College [Props=" + emails + "]";
}
}
这是我的beans.xml
spring-beans-3.0.xsd">
minemails">
最佳答案
在beans.xml中,您尝试设置CollectionsWithProps的字段adminemails.
但是该类没有该字段,它具有电子邮件字段.
但是该类没有该字段,它具有电子邮件字段.
修复beans.xml以使用电子邮件而不是adminemails,或修复CollectionsWithProps的源代码将电子邮件重命名为adminemails(以及getter和setter)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。