Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

151
Views
Spring batch with spring data

Is there a way to integrate spring batch with spring data? I see RepositoryItemReader and RepositoryItemWriter in spring documentation.

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

You are totally right. Spring batch can be easily be integrated with spring data. Here example of item reader:

    @Bean(name = "lotteryInfoReader")
    @StepScope
    public RepositoryItemReader<LotteryInfo> reader() {
        RepositoryItemReader<LotteryInfo> reader = new RepositoryItemReader<>();
        reader.setRepository(lotteryInfoRepository);
        reader.setMethodName("findAll");
        reader.setSort(Collections.singletonMap("name", Sort.Direction.ASC));
        return reader;
    }

Here is another example with using hibernate without spring data :

    @Bean(name = "drawsWriter")
    @StepScope
    public ItemWriter<? super List<Draw>> writer() {
        return items -> items.stream()
                .flatMap(Collection::stream)
                .forEach(entityManager::merge);
    }
about 4 years ago · Santiago Trujillo Report

0

well i'm doing that in a different way i'm injecting the service into the job configuration and invoke the method that's available on the JpaRepository, like this example

    @Bean
    @StepScope
    public ItemWriter<Customer> customerItemWriter2() {
        return items -> {
            for (Customer item : items) {

                customerService.save(item);
            }
        };
    }
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!