即时使用spring批处理我尝试从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
提前致谢
答案 0 :(得分:0)
名为FlatFileItemReader
的{{1}}上没有方法。这就是那个例外告诉你的。您在那里配置的属性实际上看起来像是基于JDBC的阅读器。单个平面文件无法使用Spring Batch中的现成组件进行分区。您需要将其拆分才能使用分区。