我有以下存储库:
@Repository
public interface InterlocutorRepository extends PagingAndSortingRepository<Interlocutor, UsuarioId> {
Page<Interlocutor> findByFlCadastroOnlineIn(List<StatusCadOnline> flCadastroOnline, Pageable pageable);
}
我的 Spring Batch 应用程序中有以下阅读器:
@Bean
public ItemReader<Interlocutor> reader() {
List<StatusCadOnline> listaStatusCadOnline = new ArrayList();
listaStatusCadOnline.add(StatusCadOnline.PENDENTE);
listaStatusCadOnline.add(StatusCadOnline.ERRO);
RepositoryItemReader<Interlocutor> reader = new RepositoryItemReader<>();
reader.setRepository(repository);
reader.setMethodName("findByFlCadastroOnlineIn");
reader.setArguments(listaStatusCadOnline);
HashMap<String, Sort.Direction> sorts = new HashMap<>();
sorts.put("nrCpf", Sort.Direction.ASC);
reader.setSort(sorts);
return reader;
}
Spring Batch 了解到我的方法有两个 StatusCadOnline 类型的参数,而不是单个 List 类型的参数。
日志错误:
ERROR [SimpleAsyncTaskExecutor-178] b.c.a.c.b.steps.ItemSkipPolicy.shouldSkip 12 - java.lang.NoSuchMethodException: com.sun.proxy.$Proxy84.findByFlCadastroOnlineIn(br.com.alelo.corp.core.model.enumerator.StatusCadOnline, br.com.alelo.corp.core.model.enumerator.StatusCadOnline, org.springframework.data.domain.PageRequest)
有人可以帮我吗?
谢谢
要将 JPA 的 findBy*In() 与 RepositoryItemReader 一起使用:
您需要接收参数列表,为此,您必须将属性更改为列表>
针对您的案例运行代码解决方案的示例:
...
List<List<StatusCadOnline>> arguments = new ArrayList();
List<StatusCadOnline> attributeListIn = new ArrayList();
attributeListIn.add(StatusCadOnline.PENDENTE);
attributeListIn.add(StatusCadOnline.ERRO);
arguments.add(attributeListIn);
RepositoryItemReader<Filial> reader = new RepositoryItemReader<>();
reader.setRepository(branchRepository);
reader.setMethodName("findByFlCadastroOnlineIn");
reader.setArguments(arguments);
...