java RepositoryItemReader找不到带参数的方法
我正在为springBatch步骤中的读者设置ItemRepositoryReader
public ItemReader<EcheanceEntity> reader(){
RepositoryItemReader<EcheanceEntity> reader = new RepositoryItemReader<EcheanceEntity>();
reader.setRepository(echeanceRepository);
reader.setMethodName("findById");
List parameters = new ArrayList();
long a = 0;
parameters.add(a);
reader.setArguments(parameters);
Map<String, Direction> sort = new HashMap<String, Direction>();
sort.put("id", Direction.ASC);
reader.setSort(sort);
return reader;
}
这是我存储库中的一行
public interface EcheanceRepository extends JpaRepository<EcheanceEntity, Long>{
public EcheanceEntity findById(long id);
@Override
public List<EcheanceEntity> findAll();
如果a使用findAll()方法,那么在没有任何参数的情况下,它可以正常工作。但是如果我使用findById(long id)方法,我会从ItemRepositoryReader中得到“没有这样的方法异常,findById(java.lang.long,org.springframework.data.domain.PageRequest)”。当我立即使用存储库进行测试时,该方法在不使用阅读器的情况下运行良好
谢谢
# 1 楼答案
在使用
RepositoryItemReader#setMethodName
方法的情况下,需要在存储库方法签名的最后位置添加Pageable
类型的参数:您可以在文档中找到它的描述:http://docs.spring.io/spring-batch/apidocs/org/springframework/batch/item/data/RepositoryItemReader.html#setMethodName-java.lang.String-