0

I need to configure a multi-thread job and for that, I need to paginate my data in a different class, not in the config file. I've tried literally everything and I don't know why it doesn't work when I try to create a class for the Reader.

I've tried using JdbcPagingItemReader, JpaPagingItemReader and more.

Manu
  • 21
  • 4

1 Answers1

1

I've tried literally everything and I don't know why it doesn't work when I try to create a class for the Reader.

You did not specify what does not work, but your configuration is not correct: you are declaring a @Bean in a @Component class. This class should rather be a @Configuration class:

@Cnfiguration
public class StepZeroReader{

   @Bean
   public JpaPagingItemReader<RequisicaoTrocaAssessor> reader() {
      // return an instance of JpaPagingItemReader
   }
}

Mahmoud Ben Hassine
  • 28,519
  • 3
  • 32
  • 50
  • Hey Mahmoud, thanks for your reply! I forgot to put the Error: "Field stepZeroReader in BatchConfig required a bean of type 'StepZeroReader' that could not be found." Even putting @Configuration in StepZeroReader, I've got the same error. – Manu Mar 14 '23 at 23:24
  • BatchConfig already is the Configuration class, but I want to configure the Reader in another class, such as the Processor and Writer. But when it comes to the reader, it never works – Manu Mar 14 '23 at 23:29
  • That was not clear from your description. The beans definition are pasted out of context. I can't say from what you shared why this error happens. If you share a minimal example https://stackoverflow.com/help/minimal-reproducible-example, I can try to help. – Mahmoud Ben Hassine Mar 15 '23 at 08:27
  • Hello Mahmoud, I've updated the question with an MRE and explained better what I am trying to reproduce. If you could help, I would be grateful. – Manu Mar 15 '23 at 14:12
  • 1
    `EntityManager is required when queryProvider is null`: this means the entity manager was not correctly set on the reader (probably due to a misconfiguration of the EntityManagerFactory). Otherwise, you need to set a `QueryProvider` on your item reader. – Mahmoud Ben Hassine Mar 16 '23 at 09:11