org.springframework.beans.NotWritablePropertyException: 无效的属性 bean 类'xxxx':



我是 spring 框架的新手,正在尝试使用 spring xml 创建一个 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 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)

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>

问题已解决:这是由于使用了不正确的罐子。 spring.tx 是需要使用的 jar,而我使用的是 spring.dao

最新更新