您好我是Spring批处理新手,并使用版本3.0.4.RELEASE为我的POC处理一个非常大的平面文件,如下所示。
以块处理模式运行批处理。
使用同步方法运行
自定义处理器,用于验证和转换数据。
文件格式如下。
COB_DATE HIERARCHY_NODE_ID HIERARCHY_LEVEL MEASURE CURRENCY VALUE
20151009 329715 COSTCENTER TOV_Position_60d USD 21848543.55
20151009 329715 COSTCENTER TOV_Position_90d USD 9040531.7
201510009 329715 COSTCENTER TOV_Ratio_30d 47.0069727152
20151009 329715 COSTCENTER TOV_Ratio_60d 20.2442137613
20151009 329715 COSTCENTER TOV_Ratio_90d 121.7425393354
20151009 329715 COSTCENTER TOV_Turnover_30d USD 259996659.00
我在COB_DATE字段上进行了验证,如果格式不正确,我会在处理器中抛出ValidationException。 问题是抛出验证异常之前的所有有效行,并且对于编写器不可用。在这种情况下,row1和row2。
这是作业配置
<beans:import resource="JobContext.xml" />
<!-- Starting point of the feed runner -->
<beans:bean id="feedJobRunner" class="com.ubs.risk.arisk.job.FeedJobRunner" >
<beans:constructor-arg name="jobLauncher" ref="jobLauncher"/>
<beans:constructor-arg name="job" ref="feedJob"/>
<beans:constructor-arg name="feedDao" ref="feedDao"/>
</beans:bean>
<beans:bean id="feedReader" class="com.ubs.risk.arisk.job.batch.FeedReaderDelegate" scope="step">
<beans:constructor-arg>
<beans:bean class="org.springframework.batch.item.file.FlatFileItemReader">
<beans:property name="resource" value="#{jobParameters['inputResource']}"/>
<beans:property name="linesToSkip" value="1"/>
<beans:property name="lineMapper">
<beans:bean class="org.springframework.batch.item.file.mapping.DefaultLineMapper">
<beans:property name="lineTokenizer">
<beans:bean class="org.springframework.batch.item.file.transform.DelimitedLineTokenizer">
<beans:property name="delimiter" >
<util:constant static-field="org.springframework.batch.item.file.transform.DelimitedLineTokenizer.DELIMITER_TAB" />
</beans:property>
<beans:property name="names" value="#{jobParameters['fieldNames']}"/>
<beans:property name="strict" value="false"/>
</beans:bean>
</beans:property>
<beans:property name="fieldSetMapper" >
<beans:bean class="com.ubs.risk.arisk.job.batch.FeedFieldSetMapper"/>
</beans:property>
</beans:bean>
</beans:property>
</beans:bean>
</beans:constructor-arg>
</beans:bean>
<beans:bean id="feedProcessor" class="com.ubs.risk.arisk.job.batch.FeedRowProcessor" scope="step" >
<beans:constructor-arg name="feedDao" ref="feedDao" />
<beans:constructor-arg name="stepExecution" value="#{stepExecution}"/>
</beans:bean>
<beans:bean id="feedWriter" class="com.ubs.risk.arisk.job.batch.FeedWriter" scope="step">
<beans:constructor-arg name="dataSource" ref="dataSource" />
</beans:bean>
<job id="feedJob">
<step id="importFeedStep">
<tasklet task-executor="stepExecutor" throttle-limit="10">
<chunk reader="feedReader" processor="feedProcessor" writer="feedWriter" commit-interval="300" skip-limit="100" >
<skippable-exception-classes>
<include class="com.ubs.risk.arisk.job.batch.exception.FeedValidationException"/>
</skippable-exception-classes>
<listeners>
<listener>
<beans:bean class="com.ubs.risk.arisk.job.batch.listener.FeedSkipListener">
<beans:property name="feedDao" ref="feedDao"/>
</beans:bean>
</listener>
</listeners>
</chunk>
</tasklet>
<listeners>
<listener >
<beans:bean id="feedStepListener" class="com.ubs.risk.arisk.job.batch.listener.FeedStepListener">
<beans:constructor-arg name="feedDao" ref="feedDao" />
</beans:bean>
</listener>
</listeners>
</step>
<listeners>
<listener>
<beans:bean id="feedJobListener" class="com.ubs.risk.arisk.job.batch.listener.FeedJobListener">
<beans:constructor-arg name="processDao">
<beans:bean class="com.ubs.risk.arisk.job.batch.dao.JdbcProcessDao">
<beans:property name="dataSource" ref="dataSource"/>
</beans:bean>
</beans:constructor-arg>
</beans:bean>
</listener>
</listeners>
<validator ref="jobParamValidator"/>
</job>
<beans:bean id="stepExecutor" class="org.springframework.core.task.SimpleAsyncTaskExecutor" />
<beans:bean id="jobParamValidator" class="com.ubs.risk.arisk.job.batch.validation.JobParameterValidator"/>
提前感谢任何建议。