I am working on a proof of concept using Spring Batch as a candidate for replacing our current COBOL batch architecture which was designed decades ago on a mainframe environment.
The job I decided to convert has two main steps to it.
Step 1 accesses the database to obtain a few pieces of information which will be used repeatedly in the second step. So, I only want to do this step once.
Step 2 will encompass the normal chunk, reader, processor, and writer login.
Step 1 is where I am stuck. There is no need for a reader, writer, and processor. All I need is to run a task.
I have looked at chapter 11 toward the bottom where it discusses passing data to other steps. I have attempted quit a few different approaches to getting this to work and am unsuccessful.
The problem seems to be getting the stepExecution context retrieved successfully.
The job definition from the applicationContext file is:
Code:<job id="refundExtractJob" xmlns="http://www.springframework.org/schema/batch" > <step id="startUpTasks" next="processRefunds" parent="simpleStep" > <tasklet ref="startupTasklet"> <listeners> <listener ref="promotionListener" /> <listener ref="saveStepExecutionListener"/> </listeners> </tasklet> </step> <step id="processRefunds" parent="simpleStep"> <tasklet> <chunk reader="refundReader" processor="refundProcessor" writer="refundWriter" commit-interval="10" /> </tasklet> </step> </job> <bean id="promotionListener" class="org.springframework.batch.core.listener.ExecutionContextPromotionListener"> <property name="keys" value="batchDate,uddYear,batchDateYymmdd,createTime,effectiveDate,effectiveDateYymmdd,julianDate"/> </bean> <bean id="saveStepExecutionListener" class="org.springframework.batch.core.StepExecutionListener"/> <bean id="simpleStep" class="org.springframework.batch.core.step.item.SimpleStepFactoryBean" abstract="true"> <property name="transactionManager" ref="transactionManagerMysql" /> <property name="jobRepository" ref="jobRepository" /> <property name="commitInterval" value="1" /> </bean> <bean id="startupTasklet" class="gov.azdor.refundbatch.RefundStartupTasklet" />
My class called RefundStartupTasklet class definition is:
From Chapter 11 of the guide, the key to making this all work is the method included in this class:Code:public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception
With my code, this method never gets called which means this code from chapter 11 fails:Code:@BeforeStep public void setApplicationContext(ApplicationContext arg0) throws BeansException { context = arg0; }
I did notice that the chapter class is implementing ItemWriter which I am trying to avoid.Code:ExecutionContext stepContext = this.stepExecution.getExecutionContext(); stepContext.put("someKey", someObject);
I would really appreciate any help anyone can shed on this problem.
Thanks, Steve


Reply With Quote