Giriş
Açıklaması şöyle.
Açıklaması şöyle.
by specifying a spring batch component being StepScope means that Spring Batch will use the spring container to instantiate a new instance of that component for each step execution.Örnek
Şöyle yaparız
Şöyle yaparız@Configuration@EnableBatchProcessingpublic class JobConfig {@Autowiredprivate JobBuilderFactory jobBuilderFactory;@Autowiredprivate StepBuilderFactory stepBuilderFactory;@Autowiredprivate DataSource dataSource;@Beanpublic Job job() {return jobBuilderFactory.get("job").incrementer(new RunIdIncrementer()).start(step()).build();}@Beanpublic Step step() {return stepBuilderFactory.get("step").<String, String>chunk(10).reader(reader()).processor(processor()).writer(writer()).build();}}
@Bean@StepScopepublic FlatFileItemReader<String> reader() {return new FlatFileItemReaderBuilder<String>().name("reader").resource(new ClassPathResource("input.csv")).lineMapper(new DefaultLineMapper<String>() {{setLineTokenizer(new DelimitedLineTokenizer() {{setNames(new String[]{"name"});}});setFieldSetMapper(new BeanWrapperFieldSetMapper<String>() {{setTargetType(String.class);}});}}).build();}@Bean@StepScopepublic ItemProcessor<String, String> processor() {return item -> item.toUpperCase();}@Bean@StepScopepublic JdbcBatchItemWriter<String> writer() {return new JdbcBatchItemWriterBuilder<String>().dataSource(dataSource).sql("INSERT INTO output(name) VALUES (:name)").itemSqlParameterSourceProvider(new BeanPropertyItemSqlParameterSourceProvider<>()).build();}
Hiç yorum yok:
Yorum Gönder