RepositoryItemReader:java.util.ArrayList 无法转换为 org.springframework.data.domain.Page
RepositoryItemReader: java.util.ArrayList cannot be cast to org.springframework.data.domain.Page
我正在 spring 批处理步骤中为 reader 设置 ItemRepositoryReader。我想使用 findByScenarioBetween 方法,它有两个参数,最小值和最大值。
我的仓库
public interface FuneralPricingRepository extends JpaRepository<FuneralPricing, Long> {
@Query("select p from FuneralPricing p where p.scenario between ?1 and ?2")
List<FuneralPricing> findByScenarioBetween(Long min, Long max, Pageable pageable);
}
我的Reader
@Bean
@StepScope
public ItemReader<FuneralPricing> funeralPricingRepositoryReader(
@Value("#{jobParameters[start]}") Long start,
@Value("#{jobParameters[end]}") Long end) {
RepositoryItemReader<FuneralPricing> repositoryItemReader = new RepositoryItemReader<>();
repositoryItemReader.setPageSize(10);
repositoryItemReader.setSort(funeralPricingSort());
repositoryItemReader.setRepository(funeralPricingRepository);
repositoryItemReader.setMaxItemCount(100);
repositoryItemReader.setMethodName("findByScenarioBetween");
List parameters = new ArrayList();
parameters.add(start);
parameters.add(end);
repositoryItemReader.setArguments(parameters);
return repositoryItemReader;
}
当我使用 findAll 时,它工作正常。但后来我不想每次都阅读所有行。我不知道我的 reader 中是否遗漏了什么!谢谢。
java.lang.ClassCastException: java.util.ArrayList cannot be cast to org.springframework.data.domain.Page at org.springframework.batch.item.data.RepositoryItemReader.doPageRead(RepositoryItemReader.java:208) at org.springframework.batch.item.data.RepositoryItemReader.doRead(RepositoryItemReader.java:153) at org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader.read(AbstractItemCountingItemStreamItemReader.java:88) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:302) at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:133) at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:121) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:208) at com.sun.proxy.$Proxy120.read(Unknown Source) at org.springframework.batch.core.step.item.SimpleChunkProvider.doRead(SimpleChunkProvider.java:91) at org.springframework.batch.core.step.item.SimpleChunkProvider.read(SimpleChunkProvider.java:157) at org.springframework.batch.core.step.item.SimpleChunkProvider.doInIteration(SimpleChunkProvider.java:116) at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:374) at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:215) at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:144) at org.springframework.batch.core.step.item.SimpleChunkProvider.provide(SimpleChunkProvider.java:110) at org.springframework.batch.core.step.item.ChunkOrientedTasklet.execute(ChunkOrientedTasklet.java:69) at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:406) at org.sp
将List<FuneralPricing>
更新为Page<FuneralPricing>
public interface FuneralPricingRepository extends JpaRepository<FuneralPricing, Long> {
Page<FuneralPricing> findByScenarioBetween(Long min, Long max, Pageable pageable);
}
我正在 spring 批处理步骤中为 reader 设置 ItemRepositoryReader。我想使用 findByScenarioBetween 方法,它有两个参数,最小值和最大值。
我的仓库
public interface FuneralPricingRepository extends JpaRepository<FuneralPricing, Long> {
@Query("select p from FuneralPricing p where p.scenario between ?1 and ?2")
List<FuneralPricing> findByScenarioBetween(Long min, Long max, Pageable pageable);
}
我的Reader
@Bean
@StepScope
public ItemReader<FuneralPricing> funeralPricingRepositoryReader(
@Value("#{jobParameters[start]}") Long start,
@Value("#{jobParameters[end]}") Long end) {
RepositoryItemReader<FuneralPricing> repositoryItemReader = new RepositoryItemReader<>();
repositoryItemReader.setPageSize(10);
repositoryItemReader.setSort(funeralPricingSort());
repositoryItemReader.setRepository(funeralPricingRepository);
repositoryItemReader.setMaxItemCount(100);
repositoryItemReader.setMethodName("findByScenarioBetween");
List parameters = new ArrayList();
parameters.add(start);
parameters.add(end);
repositoryItemReader.setArguments(parameters);
return repositoryItemReader;
}
当我使用 findAll 时,它工作正常。但后来我不想每次都阅读所有行。我不知道我的 reader 中是否遗漏了什么!谢谢。
java.lang.ClassCastException: java.util.ArrayList cannot be cast to org.springframework.data.domain.Page at org.springframework.batch.item.data.RepositoryItemReader.doPageRead(RepositoryItemReader.java:208) at org.springframework.batch.item.data.RepositoryItemReader.doRead(RepositoryItemReader.java:153) at org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader.read(AbstractItemCountingItemStreamItemReader.java:88) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:302) at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:133) at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:121) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:208) at com.sun.proxy.$Proxy120.read(Unknown Source) at org.springframework.batch.core.step.item.SimpleChunkProvider.doRead(SimpleChunkProvider.java:91) at org.springframework.batch.core.step.item.SimpleChunkProvider.read(SimpleChunkProvider.java:157) at org.springframework.batch.core.step.item.SimpleChunkProvider.doInIteration(SimpleChunkProvider.java:116) at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:374) at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:215) at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:144) at org.springframework.batch.core.step.item.SimpleChunkProvider.provide(SimpleChunkProvider.java:110) at org.springframework.batch.core.step.item.ChunkOrientedTasklet.execute(ChunkOrientedTasklet.java:69) at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:406) at org.sp
将List<FuneralPricing>
更新为Page<FuneralPricing>
public interface FuneralPricingRepository extends JpaRepository<FuneralPricing, Long> {
Page<FuneralPricing> findByScenarioBetween(Long min, Long max, Pageable pageable);
}