Hi everyone, I have pretty much solved my external mapping issue however have one additional problem to solve for.
I would like to be able to modify the resource property of FlatFileItemReader at runtime with a value sourced earlier in the job.
I have the current job:
mappingLoaderTasklet is used to load a static class with some mapping details from an external configuration file that can be used throughout the job.Code:<job id="processTrades"> <step id="step1" next="step2"> <tasklet ref="mappingLoaderTasklet" /> </step> <step id="step2"> <tasklet> <chunk reader="tradeReader" processor="tradeProcessor" writer="tradeWriter" commit-interval="1" /> </tasklet> </step> </job>
One of these mapping fields is the input file location that I want used by the ItemReader. I would like to be able to effectively do the following:Code:package com.windebank.projects.tradeloader; import org.apache.log4j.Logger; import org.springframework.batch.core.StepContribution; import org.springframework.batch.core.scope.context.ChunkContext; import org.springframework.batch.core.step.tasklet.Tasklet; import org.springframework.batch.repeat.RepeatStatus; public class MappingLoaderTasklet implements Tasklet { final Logger logger = Logger.getLogger(MappingLoaderTasklet.class); private String inputFile; public String getInputFile() { return inputFile; } public void setInputFile(String inputFile) { this.inputFile = inputFile; } public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception { TradeMapping.inputFile = inputFile; TradeMapping.read(); logger.info("MappingLoaderTasklet: " + inputFile); return null; } }
I just don't know how this can work when interacting with the beans. I know I can use late binding from the JobParameters as follows:Code:FlatFileItemReader.resource = TradeMapping.fileName
However this still isn't late enough binding for what I want.Code:<beans:bean name="tradeReader" class="org.springframework.batch.item.file.FlatFileItemReader" scope="step"> <beans:property name="lineMapper" ref="tradeLineMapper" /> <beans:property name="resource" value="#{jobParameters['inputFile']}" /> </beans:bean>
Anyone got any ideas please?



Reply With Quote