java设计阅读器步骤_如何工作(工作流程)项目编写器,项目阅读器, Spring 季批处理项目处理器...

我已经使用java注释编写了一个简单的 spring 批处理应用程序,其中包含自定义项目阅读器,项目处理器和项目编写器 . 但我无法理解这个工作流程 . 如果有人能够描述读者,作者和处理器在 Spring 天如何工作,那将非常有用批量 .

主要课程

@SpringBootApplication

@ComponentScan({"com.test"})

public class TestBatch implements CommandLineRunner {

public static void main(String[] args) throws Exception {

SpringApplication app = new SpringApplication(TestConfig.class);

ConfigurableApplicationContext ctx = app.run(args);

JobLauncher jobLauncher = ctx.getBean(JobLauncher.class);

Job jobOne = ctx.getBean("jobOne", Job.class);

JobParameters jobOneParams = new JobParametersBuilder().addDate("date", new Date()).toJobParameters();

JobExecution jobExcecution = jobLauncher.run(jobOne,jobOneParams);

System.out.println("Status -->"+jobExcecution.getStatus());

}

@Override

public void run(String... arg) throws Exception {

System.out.println("running -->");

}

}

配置类

public class TestConfig {

@Autowired

public JobBuilderFactory jobBuilderFactory;

@Autowired

public StepBuilderFactory stepBuilderFactory;

@Bean

public Job jobOne(){

return jobBuilderFactory.get("job")

.incrementer(new RunIdIncrementer())

.listener(listener())

.flow(stepOne())

.end()

.build();

}

@Bean

public Step stepOne(){

return stepBuilderFactory.get("stepone")

. chunk(1)

.reader(reader())

.processor(processor())

.writer(writer())

.build();

}

@Bean

public ItemReader reader() {

return new MyItemReader();

}

@Bean

public ItemProcessor processor() {

return new MyItemProcessor();

}

@Bean

public ItemWriter writer() {

return new MyItemItemWriter();

}

@Bean

public JobExecutionListener listener() {

return new MyListener();

}

}

读者课

@Scope("step")

public class MyItemReader implements ItemReader{

Logger logger = LoggerFactory.getLogger(this.getClass());

private String date;

@Override

public String read() throws Exception, UnexpectedInputException, ParseException, NonTransientResourceException {

System.out.println("---Reading---");

return "test";

}

}

处理器类

public class MyItemProcessor implements ItemProcessor{

@Override

public String process(String content) throws Exception {

System.out.println("---processing---");

return content.toUpperCase();

}

}

作家卡尔斯

public class MyItemItemWriter implements ItemWriter{

Logger logger = LoggerFactory.getLogger(this.getClass());

@Override

public void write(List extends String> messages) throws Exception {

for(String msg : messages){

System.out.println("writing-->" + msg);

}

}

}

提前致谢 .

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值