spring batch - @BeforeStep annotated method not being called -
i writing spring batch job. when archive class implenets tasklet interface in loaded, method under annotation @beforestep not being called. can me ? thank you
import java.io.file; import java.io.fileinputstream; import java.io.fileoutputstream; import java.io.ioexception; import java.nio.file.files; import java.nio.file.standardcopyoption; import java.util.calendar; import java.util.locale; import java.util.timezone; import java.util.zip.zipentry; import java.util.zip.zipoutputstream; import org.springframework.batch.core.jobexecution; import org.springframework.batch.core.stepcontribution; import org.springframework.batch.core.stepexecution; import org.springframework.batch.core.annotation.beforestep; import org.springframework.batch.core.scope.context.chunkcontext; import org.springframework.batch.core.step.tasklet.tasklet; import org.springframework.batch.item.executioncontext; import org.springframework.batch.repeat.repeatstatus; public class archive implements tasklet{ @override public repeatstatus execute(stepcontribution arg0, chunkcontext arg1) throws exception { system.out.println("in execute method :)"); return repeatstatus.finished; } @beforestep public void retrieveinterstepdata(stepexecution stepexecution){ jobexecution jobexecution = stepexecution.getjobexecution(); executioncontext jobcontext = jobexecution.getexecutioncontext(); } }
first solution can extract executioncontext
execute
method have chunkcontext
, whatever need.
executioncontext jobcontext = chunkcontext.getstepcontext() .getstepexecution() .getjobexecution() .getexecutioncontext();
second solution can implement stepexecutionlistener
, override beforestep
method. have like:
public class archive implements tasklet, stepexecutionlistener{ @override public repeatstatus execute(stepcontribution arg0, chunkcontext arg1) throws exception { system.out.println("in execute method :)"); return repeatstatus.finished; } @override public void beforestep(final stepexecution stepexecution) { jobexecution jobexecution = stepexecution.getjobexecution(); executioncontext jobcontext = jobexecution.getexecutioncontext(); } }
i had similar problem , overcomed this. why @beforestep
not called on tasklet inside readers
, processors
, writers
not sure.
Comments
Post a Comment