【发布时间】:2017-11-04 07:13:16
【问题描述】:
步骤类:GenerateReferenceNumber
package com.npst.imps.action;
import org.springframework.batch.core.StepContribution;
import org.springframework.batch.core.scope.context.ChunkContext;
import org.springframework.batch.core.step.tasklet.Tasklet;
import org.springframework.batch.repeat.RepeatStatus;
import com.npst.imps.utils.TransactionResponseData;
public class GenerateReferenceNumber implements Tasklet {
@Override
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
double rrn= Math.random();
chunkContext.getStepContext().getStepExecution().getJobExecution().getExecutionContext().put("rrn", rrn);
double tid= (double) chunkContext.getStepContext().getStepExecution().getJobExecution().getExecutionContext().get("tid");
chunkContext.getStepContext().getStepExecution().getJobExecution().getExecutionContext().put("trnsactionstatus", "RRN generated for Tid::"+tid+" is "+rrn);
TransactionResponseData transactionResponseData =(TransactionResponseData) chunkContext.getStepContext().getStepExecution().getJobExecution().getExecutionContext().get("transactionResponseData");
transactionResponseData.setRrn(rrn+"");
chunkContext.getStepContext().getStepExecution().getJobExecution().getExecutionContext().put("transactionResponseData", transactionResponseData);
return RepeatStatus.FINISHED;
}
}
而不是 Repeatstatus.FINISHED ,我怎样才能返回我自己定义的状态,并根据它们决定下一步。自定义状态,如成功、失败、部分等。
批处理作业.xml
<beans:beans xmlns="http://www.springframework.org/schema/batch"
xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/batch
http://www.springframework.org/schema/batch/spring-batch-3.0.xsd">
<job id="MBSFT">
<step id="PrepareTid" allow-start-if-complete="true" next="PrepareRRN">
<tasklet ref="PrepareTransactionId" />
</step>
<step id="PrepareRRN" allow-start-if-complete="true">
<tasklet ref="GenerateReferenceNumber" />
<next on="COMPLETED" to="IdentifyImpsService" />
</step>
<step id="IdentifyImpsService" allow-start-if-complete="true">
<tasklet ref="IdentifyIMPSRequestType" />
<next on="COMPLETED" to="FetchNBIN" />
</step>
<step id="FetchNBIN" allow-start-if-complete="true">
<tasklet ref="FetchNBINFromIFSC" />
</step>
</job>
</beans:beans>
【问题讨论】:
标签: java spring spring-boot spring-batch