Java org.springframework.beans.NotWritablePropertyException:无效属性';xxxx和x27;bean类的名称:
我是spring框架的新手,曾试图使用SpringXML创建一个bean,但现在我面临以下异常Java org.springframework.beans.NotWritablePropertyException:无效属性';xxxx和x27;bean类的名称:,java,spring-mvc,Java,Spring Mvc,我是spring框架的新手,曾试图使用SpringXML创建一个bean,但现在我面临以下异常 Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'feedServerLineRead' defined in class path resource [FeedServer.xml]: Error setting prop
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'feedServerLineRead' defined in class path resource [FeedServer.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'feedProcessor' of bean class [workflow.FeedServerLineRead]: Bean property 'feedProcessor' 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:1361)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1086)
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:291)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:728)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:380)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at controller.FeedController.main(FeedController.java:76)
Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'feedProcessor' of bean class [workflow.FeedServerLineRead]: Bean property 'feedProcessor' 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:1024)
at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:900)
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:1358)
线程“main”org.springframework.beans.factory.BeanCreationException中的异常:创建名为“feedServerLineRead”的bean时出错,该bean在类路径资源[FeedServer.xml]中定义:设置属性值时出错;嵌套异常为org.springframework.beans.NotWritablePropertyException:bean类[workflow.FeedServerLineRead]的无效属性“feedProcessor”:bean属性“feedProcessor”不可写或具有无效的setter方法。setter的参数类型与getter的返回类型匹配吗?
位于org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1361)
位于org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1086)
位于org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
位于org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
位于org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
位于org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
位于org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
位于org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
位于org.springframework.beans.factory.support.DefaultListableBeanFactory.PreInstanceSingleton(DefaultListableBeanFactory.java:580)
位于org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:728)
位于org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:380)
位于org.springframework.context.support.ClassPathXmlApplicationContext。(ClassPathXmlApplicationContext.java:139)
位于org.springframework.context.support.ClassPathXmlApplicationContext。(ClassPathXmlApplicationContext.java:83)
位于controller.FeedController.main(FeedController.java:76)
原因:org.springframework.beans.NotWritablePropertyException:bean类[workflow.FeedServerLineRead]的属性“feedProcessor”无效:bean属性“feedProcessor”不可写或具有无效的setter方法。setter的参数类型与getter的返回类型匹配吗?
位于org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:1024)
位于org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:900)
位于org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:76)
位于org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:58)
位于org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1358)
包工作流;
导入java.util.ArrayList;
导入java.util.List;
导入java.util.concurrent.BlockingQueue;
导入org.springframework.jmx.export.annotation.ManagedResource;
输入数据;
进口饲料处理机;
@ManagedResource(objectName=“bean:name=FeedServerLineRead”)
公共类FeedServerLineRead实现可运行{
专用反馈处理器;
阻塞队列;
@凌驾
公开募捐{
while(true){
捆绑某人;
试一试{
sb=queue.take();
List beanList=new ArrayList();
FeedData dataPojo=新的FeedData();
dataPojo.setSide(sb.charAt(60));
dataPojo.setProduct(sb.substring(145163));
添加(dataPojo);
feedProcessor.insertBatch(beanList);
}捕获(中断异常例外){
打破
}
}
}
公共FeedServerLineRead(){
this.queue=null;
}
公共FeedServerLineRead(阻塞队列){
this.queue=队列;
}
公共FeedProcessor getFeedProcessor(){
回馈处理机;
}
公共无效setFeedProcessor(FeedProcessor FeedProcessor){
this.feedProcessor=feedProcessor;
}
}
问题已解决:这是由于使用了不正确的jar。spring.tx是需要使用的jar,而我使用的是spring.dao。问题得到了解决:这是由于使用了不正确的jar。tx是需要使用的jar,而我使用的是spring.dao
package workflow;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.BlockingQueue;
import org.springframework.jmx.export.annotation.ManagedResource;
import FeedData;
import FeedProcessor;
@ManagedResource(objectName="bean:name=FeedServerLineRead")
public class FeedServerLineRead implements Runnable {
private FeedProcessor feedProcessor;
BlockingQueue<String> queue;
@Override
public void run() {
while(true) {
String sb;
try {
sb = queue.take();
List <FeedData> beanList = new ArrayList<FeedData>();
FeedData dataPojo = new FeedData();
dataPojo.setSide(sb.charAt(60));
dataPojo.setProduct(sb.substring(145, 163));
beanList.add(dataPojo);
feedProcessor.insertBatch(beanList);
} catch (InterruptedException ex) {
break;
}
}
}
public FeedServerLineRead(){
this.queue=null;
}
public FeedServerLineRead(BlockingQueue<String> queue) {
this.queue = queue;
}
public FeedProcessor getFeedProcessor() {
return feedProcessor;
}
public void setFeedProcessor(FeedProcessor feedProcessor) {
this.feedProcessor = feedProcessor;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<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"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-3.0.xsd
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-3.0.xsd">
<bean id="feedProcessor" class="processor.FeedProcessor" />
<bean id="feedServerLineRead" class="workflow.FeedServerLineRead">
<property name="feedProcessor" ref="feedProcessor" />
</bean>
</beans>