spring - How to get value from StepExecutionContext -


i have spring batch jdbccursoritemreader. defined @jobscope. see method signature below.

@bean @jobscope public jdbccursoritemreader<masterlist> querystagingdbreader(         @value("#{jobparameters['" + jobparamconstants.param_from_date + "']}") date jobfromdate,         @value("#{jobparameters['" + jobparamconstants.param_to_date + "']}") date jobtodate) { 

this jdbccursoritemreader part of step 2 in job.

in step 1 of job have tasklet. inside tasklet building list of dates jdbccursoritemreader in step 2 know about.

my initial thought add list of dates stepexecutioncontext in tasklet so.

@bean @jobscope public tasklet createjobdatestasklet(         @value("#{jobparameters['" + jobparamconstants.param_from_date + "']}") date jobfromdate,         @value("#{jobparameters['" + jobparamconstants.param_to_date + "']}") date jobtodate) {      return new tasklet() {          @override         public repeatstatus execute(stepcontribution contribution, chunkcontext chunkcontext) throws exception {             localdate start = jobfromdate.toinstant().atzone(zoneid.systemdefault()).tolocaldate();             localdate end = jobtodate.toinstant().atzone(zoneid.systemdefault()).tolocaldate();              list<localdate> jobdates = new arraylist<>();             while (!start.isafter(end)) {                 jobdates.add(start);                 start = start.plusdays(1);             }             //adding context here             chunkcontext.getstepcontext().getstepexecution().getexecutioncontext().put("jobdates", jobdates);             return repeatstatus.finished;         }     }; } 

and grab list of dates jdbccursoritemreader. when try grab step execution context inside jdbccursoritemreader tells me cannot wire in. , think because bean @jobscope.

what can grab list of dates stepexecutioncontext or alternatively can else make work me?

thanks in advance

you cannot write step context, rather write job context, steps of job have access data below.

 stepcontext stepcontext         = chunkcontext.getstepcontext();  stepexecution stepexecution     = stepcontext.getstepexecution();  jobexecution jobexecution         = stepexecution.getjobexecution();  executioncontext jobcontext     = jobexecution.getexecutioncontext();  jobcontext.put("jobdates", jobdates); 

the below blog speaks it

http://techie-mixture.blogspot.com/2016/07/passing-values-between-spring-batch.html


Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -