为什么我得到"无法转换属性值"对于Spring中的Bean批处理

时间:2016-07-26 16:32:49

标签: java spring spring-batch

我的Spring Batch项目中有三个步骤,所有三个步骤都有readerwriterprocessor。前两步有相同的读者和处理器和作家。然而,第三步writer略有不同。请看下面的

    <bean id="stepWriter"   class="org.springframework.batch.item.database.JdbcBatchItemWriter">
    <property name="dataSource" ref="dataSource" />
    <property name="sql">
        <value>
            <![CDATA[        
                 insert into step(tst_id)
                values (?); 
           ]]>
        </value>
    </property>
    <property name="ItemPreparedStatementSetter">
        <bean class="com.preparedstatement.StepWriter" />
    </property>
</bean>

    <batch:step id="step3">
        <batch:tasklet transaction-manager="transactionManager">
            <batch:chunk reader="xmlItemReaderStep2" writer="stepWriter"
                processor="itemProcessor4" commit-interval="100" />
            <batch:listeners>
                <batch:listener ref="jobListener4" />
            </batch:listeners>
        </batch:tasklet>
    </batch:step>
    <batch:listeners>
        <batch:listener ref="jobListener1" />
    </batch:listeners>
</batch:job>

我的ItemWriter课程是

public class StepWriter implements ItemWriter<List<StepNode>> {

@Override
public void write(List<? extends List<StepNode>> stepNodeList) throws Exception {
    for (List<StepNode> list : stepNodeList) {
        for (StepNode stepNode : list) {
            //write to database
        }
    }

}
}

错误讯息:

Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘stepWriter' defined in class path resource [spring-batch-context.xml]: Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'compreparedstatement.StepWriter' to required type 'org.springframework.batch.item.database.ItemPreparedStatementSetter' for property 'ItemPreparedStatementSetter'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [com.preparedstatement.StepWriter] to required type [org.springframework.batch.item.database.ItemPreparedStatementSetter] for property 'ItemPreparedStatementSetter': 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:475)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:703)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at com.JobRunner.main(JobRunner.java:23)

Caused by: org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'com.preparedstatement.StepWriter' to required type 'org.springframework.batch.item.database.ItemPreparedStatementSetter' for property 'ItemPreparedStatementSetter'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [com.preparedstatement.StepWriter] to required type [org.springframework.batch.item.database.ItemPreparedStatementSetter] for property 'ItemPreparedStatementSetter': no matching editors or conversion strategy found
    at org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:474)
    at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:511)
    at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:505)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1502)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1461)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1197)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
    ... 11 more
Caused by: java.lang.IllegalStateException: Cannot convert value of type [com.preparedstatement.StepWriter] to required type [org.springframework.batch.item.database.ItemPreparedStatementSetter] for property 'ItemPreparedStatementSetter': no matching editors or conversion strategy found
    at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:267)
    at org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:459)
    ... 17 more

0 个答案:

没有答案