Dynamically configure a Job in spring-batch -


is possible dynamically configure job in spring-batch?

here want do. have created several different itemreader, itemwriter below:

  • flatfileitemreader
  • dbitemreader
  • flatfileitemwriter
  • dbitemwriter
  • .....
  • xmlitemwriter

i want able mix , match them dynamically while creating batch job. example, suppose need job 2 steps. first step contains tasklet pre-processing. second step have tasklet chunk based data processing using reader/writer.... this:

// define job parameters jobparametersbuilder parameters = new jobparametersbuilder();  // create 2 steps taskletstep step1 = new taskletstep();  taskletstep step2 = new taskletstep(); step1.setname("preprocessingstep"); step2.setname("chunkreadwritestep");  // create 2 tasklets tasklet tasklet1 = new preprocessingtasklet(); tasklet tasklet2; <------ how attach reader/writer in tasklet??  // attach tasklet step step1.settasklet(tasklet1); step2.settasklet(tasklet2);  // attach steps job simplejob job = new simplejob("mybatchjob"); job.addstep(step1); job.addstep(step2);   joblauncher.run(job, parameters.tojobparameters()); 

in xml, can below:

<job id="mybatchjob">     <step id="preprocessing" next="readwritestep">         <tasklet ref="preprocessingtasklet"/>     </step>     <step id="readwritestep">         <tasklet>             <chunk reader="flatfileitemreader" writer="dbitemwriter"/>         </tasklet>     </step> </job> 

but how do programatically above?

spring batch provides java based configuration building of jobs via java code instead of xml. using provided builders, can dynamically construct jobs need. i'd suggest using method instead of wiring chunkorientedtasklet hand since there quite bit going on in particular tasklet.

the best place started spring batch's java configuration in spring batch guide: http://spring.io/guides/gs/batch-processing/. it's 15 minute walk through on getting started spring batch using tools spring boot , java configuration.


Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -