RepositoryItemReader doesn’t find methods with arguments

I’m setting up an ItemRepositoryReader for the reader in a springBatch step.

public ItemReader<EcheanceEntity> reader(){
    RepositoryItemReader<EcheanceEntity> reader = new RepositoryItemReader<EcheanceEntity>();
    List parameters = new ArrayList();
    long a = 0;
    Map<String, Direction> sort = new HashMap<String, Direction>();
    sort.put("id", Direction.ASC);
    return reader;

this is the line in my repository.

public interface EcheanceRepository extends JpaRepository<EcheanceEntity, Long>{

public EcheanceEntity findById(long id);

public List<EcheanceEntity> findAll();

If a use the method findAll(), so without any arguments, it works fine. But if I use the method findById(long id) I get “no such method exception, findById(java.lang.Long,” from the ItemRepositoryReader. The method works fine without using the reader when I’m testing it by using immediately the repository.

Thank you.


In a case of using the RepositoryItemReader#setMethodName method you need to add an argument of type Pageable in your repository method signature at last position:

    public interface EcheanceRepository extends JpaRepository<EcheanceEntity, Long> {
        public Page<EcheanceEntity> findById(long id, Pageable pageable);

You can find description of it in the documentation:

public void setMethodName(java.lang.String methodName)

Specifies what method on the repository to call. This method must take Pageable as the last argument.

Leave a Reply

Your email address will not be published. Required fields are marked *