-
Notifications
You must be signed in to change notification settings - Fork 5
/
BatchConfiguration.java
56 lines (48 loc) · 1.91 KB
/
BatchConfiguration.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package scratches.boot.batchrest.batch;
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.batch.core.configuration.annotation.StepBuilderFactory;
import org.springframework.batch.core.launch.support.RunIdIncrementer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import scratches.boot.batchrest.batch.post.PostItemProcessor;
import scratches.boot.batchrest.batch.post.PostItemWriter;
import scratches.boot.batchrest.batch.user.UserItemReader;
import scratches.boot.batchrest.post.Post;
import scratches.boot.batchrest.post.PostRestRepository;
import scratches.boot.batchrest.user.User;
import scratches.boot.batchrest.user.UserRestRepository;
/**
* @author Rashidi Zin
*/
@Configuration
@EnableBatchProcessing
public class BatchConfiguration {
@Bean
public UserItemReader userItemReader(UserRestRepository repository) {
return new UserItemReader(repository);
}
@Bean
public PostItemProcessor postItemProcessor() {
return new PostItemProcessor();
}
@Bean
public PostItemWriter postItemWriter(PostRestRepository repository) {
return new PostItemWriter(repository);
}
@Bean
public Step postStep(StepBuilderFactory factory, UserItemReader reader, PostItemWriter writer) {
return factory.get("postStep")
.<User, Post>chunk(1)
.reader(reader)
.processor(postItemProcessor())
.writer(writer)
.build();
}
@Bean
public Job postJob(JobBuilderFactory factory, Step postStep) {
return factory.get("postJob").incrementer(new RunIdIncrementer()).flow(postStep).end().build();
}
}