spring batch#6
Conversation
| ru.otus.spring.hw.kanban.domain.mongo.Board mongoBoard = new ru.otus.spring.hw.kanban.domain.mongo.Board(); | ||
| mongoBoard.setName(board.getName()); | ||
|
|
||
| List<Stage> stages = stageRepository.findStagesByBoard(board); |
There was a problem hiding this comment.
Делать запрос внутри Processor не совсем правильно, лучше будет сконфигурировать reader таким образом чтобы он сразу доставал stages.
There was a problem hiding this comment.
тут не понял как это сделать, если мы уже готовый пакетный ридер возвращаем. делать fetchtype - eager не хочется.
|
|
||
| @Bean | ||
| public ItemReader<Board> reader() { | ||
| return new ItemReader<Board>() { |
There was a problem hiding this comment.
Кстати кастомный ридер здесь совсем не обязательно, spring batch очень крут тем что имеет много готовых компонентов для большинства задач.
There was a problem hiding this comment.
применил RepositoryItemReader
|
|
||
| @Bean | ||
| public ItemWriter<ru.otus.spring.hw.kanban.domain.mongo.Board> writer() { | ||
| return items -> items.forEach(o -> boardMongoRepository.save(o)); |
There was a problem hiding this comment.
Вот так точно не надо делать :) даже если мы пишем кастомный writer, есть repository.saveAll(). А вообще здесь легко будет использовать MongoItemWriter.
There was a problem hiding this comment.
переделал на монго итем врайтер
ДЗ #14, spring batch. запускается на старте приложения