【问题标题】:Invalid property 'parameterValues' of bean class [org.springframework.batch.item.file.FlatFileItemReader]bean 类 [org.springframework.batch.item.file.FlatFileItemReader] 的无效属性“parameterValues”
【发布时间】:2018-10-25 04:20:07
【问题描述】:

我正在使用 Spring Batch 我正在尝试从 csv 文件导入数据,然后使用分区概念将结果存储在 xml 文件中。

 <bean id="flatFileItemReader" class="org.springframework.batch.item.file.FlatFileItemReader"  scope="step"> 

        <property name="resource" value="classpath:ExamResult.txt" />

        <property name="lineMapper">

            <bean class="org.springframework.batch.item.file.mapping.DefaultLineMapper">

                <property name="fieldSetMapper">
                    <!-- Mapper which maps each individual items in a record to properties in POJO -->
                    <bean class="com.websystique.springbatch.ExamResultFieldSetMapper" />
                </property>

                <property name="lineTokenizer">
                    <!-- A tokenizer class to be used when items in input record are separated by specific characters -->
                    <bean class="org.springframework.batch.item.file.transform.DelimitedLineTokenizer">
                        <property name="delimiter" value="|" />
                    </bean>
                </property>

            </bean>

        </property>
                 <!-- Inject via the ExecutionContext in rangePartitioner -->

                 <property name="parameterValues">
                     <map>
                        <entry key="startingIndex" value="#{stepExecutionContext[startingIndex]}" />
                        <entry key="endingIndex" value="#{stepExecutionContext[endingIndex]}" />
                     </map>
                </property>
                <property name="pageSize" value="5" />
                    <property name="rowMapper">
                        <bean class="com.websystique.springbatch.ExamResultFieldSetMapper" />
                </property>

                </bean>

因为使用这个阅读器我得到以下错误。

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.flatFileItemReader' defined in class path resource [spring-batch-context.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'parameterValues' of bean class [org.springframework.batch.item.file.FlatFileItemReader]: Bean property 'parameterValues' 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:1493)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1197)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
    at org.springframework.beans.factory.support.AbstractBeanFactory$2.getObject(AbstractBeanFactory.java:341)
    at org.springframework.batch.core.scope.StepScope.get(StepScope.java:110)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:336)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
    at org.springframework.aop.target.SimpleBeanTargetSource.getTarget(SimpleBeanTargetSource.java:35)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:187)
    at com.sun.proxy.$Proxy2.open(Unknown Source)
    at org.springframework.batch.item.support.CompositeItemStream.open(CompositeItemStream.java:96)
    at org.springframework.batch.core.step.tasklet.TaskletStep.open(TaskletStep.java:310)
    at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:195)
    at org.springframework.batch.core.partition.support.TaskExecutorPartitionHandler$1.call(TaskExecutorPartitionHandler.java:139)
    at org.springframework.batch.core.partition.support.TaskExecutorPartitionHandler$1.call(TaskExecutorPartitionHandler.java:136)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.lang.Thread.run(Thread.java:745)
Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'parameterValues' of bean class [org.springframework.batch.item.file.FlatFileItemReader]: Bean property 'parameterValues' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?

请建议我使用合适的阅读器对数据文件进行分区。

我使用了 FlatFileItemReader

提前致谢

【问题讨论】:

    标签: java spring spring-batch


    【解决方案1】:

    FlatFileItemReader 上没有名为setParameterValues 的方法。这就是那个异常告诉你的。您在那里配置的属性实际上看起来像是用于基于 JDBC 的阅读器。单个平面文件无法使用 Spring Batch 中的开箱即用组件进行分区。您需要拆分它以使用分区。

    【讨论】:

      猜你喜欢
      • 2013-12-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-26
      • 2015-10-21
      • 1970-01-01
      • 2019-12-01
      相关资源
      最近更新 更多