JdbcBatchItemWriter
ORM을 사용하지 않는 경우 Writer는 대부분 JdbcBatchItemWriter를 사용
@Bean
public JdbcBatchItemWriter<User> jdbcBatchItemWriter() {
String sql = "INSERT INTO User(name, address) values (:name, :address)";
return new JdbcBatchItemWriterBuilder<User>()
.dataSource(dataSource) //DataSource DI
.sql(sql)
.beanMapped()
.build();
}
RepositoryItemWriter
@Bean
public RepositoryItemWriter<User> repositoryItemWriter() {
return new RepositoryItemWriterBuilder<User>()
.repository(userRepository) //UserRepository DI
.methodName("save")
.build();
}
MongoItemWriter
@Bean
public MongoItemWriter<User> mongoItemWriter() {
MongoItemWriter<User> mongoItemWriter = new MongoItemWriter<>();
mongoItemWriter.setTemplate(mongoTemplate); //MongoTemplate DI
mongoItemWriter.setCollection("User");
return mongoItemWriter;
}
MongoBulkWriter 가 필요하다면 https://tjsdud4634.tistory.com/17?category=368184 참조!
참고
https://jojoldu.tistory.com/339?category=635883
'Spring' 카테고리의 다른 글
[Spring Batch] ItemReader (0) | 2020.01.09 |
---|---|
[Spring Batch] Dynamic Scheduler 다이나믹 스케쥴링 (0) | 2020.01.09 |
[Spring Batch] MongoItemWriter 구현 (0) | 2020.01.09 |
[개념] Spring Batch 란? (0) | 2020.01.08 |