Spring Batch -@BeforeStep not getting invoked in Partitioner -


we trying implement batch job using spring batch partitioning.in in "step 2" partitioned step need data step 1 processing.i used stepexecutioncontext promoted job execution context @ step1 store data.

i tried use @beforestep annotation in partitioner class stepexecutioncontext can extract data stored , put in executioncontext of partitioner .but method @beforestep annotation not getting invoked in partitioner.

is there other way achieve this.

partitioner implementation

public class ntfnpartitioner implements partitioner {      private int index = 0;     string prev_job_time  = null;     string curr_job_time  = null;      private stepexecution stepexecution ;     executioncontext executioncontext ;      @override     public map<string, executioncontext> partition(int gridsize)     {             system.out.println("entered partitioner");            list<integer> referencids = new arraylist<integer>();            (int = 0; < gridsize;i++) {             referencids.add(index++);            }            map<string, executioncontext> results = new linkedhashmap<string,executioncontext>();           (int referencid : referencids) {             executioncontext context = new executioncontext();             context.put("referenceid", referencid);             context.put(ntfnconstants.previous_job_time, prev_job_time);             context.put(ntfnconstants.job_start_time, curr_job_time);             results.put("partition." + referencid, context);           }             return results;         }      @beforestep     public void beforestep(stepexecution stepexecution) {         // todo auto-generated method stub           system.out.println("entered before step in partion");           jobexecution jobexecution = stepexecution.getjobexecution();           executioncontext jobcontext = jobexecution.getexecutioncontext();           system.out.println("executioncontext"+jobcontext);           string prev_job_time  = (string) jobcontext.get(ntfnconstants.previous_job_time);           string curr_job_time  = (string) jobcontext.get(ntfnconstants.job_start_time);       } 

the bean should step scoped.

java, annotate class:

@stepscope 

xml, in bean definition:

scope="step" 

also @ answer regarding proxied bean (not sure if applies since no other code partitioner provided). in case can still add partitioner listener explicitly during step building:

@autowired private ntfnpartitioner partitioner;      ...  final step masterstep = stepbuilderfactory.get("master")                     .listener(partitioner)                     .partitioner("slave", partitioner)                     .step(slave)                     ... 

or if partitioner not bean (e.g. creating based on dynamic), can still add listener:

final ntfnpartitioner partitioner = new ntfnpartitioner();     final step masterstep = stepbuilderfactory.get("master")                     .listener(partitioner)                     .partitioner("slave", partitioner)                     .step(slave)                     ... 

Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -