1 回答

TA貢獻(xiàn)1784條經(jīng)驗(yàn) 獲得超7個(gè)贊
下面是一個(gè)示例。創(chuàng)建一個(gè)類(lèi),在其中定義步驟:
import org.springframework.batch.core.Step;
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class StepConfig {
@Autowired
private StepBuilderFactory steps;
@Bean
public Step step() {
return steps.get("step")
.tasklet((contribution, chunkContext) -> {
System.out.println("hello world");
return RepeatStatus.FINISHED;
})
.build();
}
}
然后在作業(yè)配置中導(dǎo)入該類(lèi):
import org.springframework.batch.core.Job;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
@EnableBatchProcessing
@Configuration
@Import(StepConfig.class)
public class JobConfig {
@Autowired
private JobBuilderFactory jobs;
@Bean
public Job job(Step step) {
return jobs.get("job")
.start(step)
.build();
}
}
希望這有幫助。
添加回答
舉報(bào)