任何想法为什么我可以通过以下代码获得以下错误?
@Bean
@StepScope
public ItemReader<OrderDetail> reader(@Value("#{jobParameters['orderDate']}") final String orderDate)
throws UnexpectedInputException, ParseException, Exception {
LOGGER.info("START of reader() with args: ", orderDate);
final Date beginDate = new Date();
final Date endDate = new Date();
final Map<String, Object> parameterValues = new HashMap<>();
parameterValues.put("beginDate", beginDate);
parameterValues.put("endDate", endDate);
final HibernateCursorItemReader<OrderDetail> itemReader = new HibernateCursorItemReader<>();
itemReader.setQueryString("select dtl from OrderDetail dtl join OrderSummary sumy on dtl.orderId = sumy.id where orderDate between
:beginDate and :endDate order by id desc");
itemReader.setParameterValues(parameterValues);
itemReader.setSessionFactory(sessionFactory);
itemReader.setUseStatelessSession(true);
itemReader.afterPropertiesSet();
LOGGER.info("END of reader()");
return itemReader;
}
java.lang.NullPointerException:null at org.springframework.batch.item.database.HibernateCursorItemReader.doRead(HibernateCursorItemReader.java:155)
在 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) 在 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 在java.lang.reflect.Method.invoke(Method.java:498)at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:333) 在 org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190) 在 org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) 在 org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:133) 在 org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:121) 在 org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) 在 org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213) 在com.sun.proxy。$ Proxy245.read(未知来源)at org.springframework.batch.core.step.item.SimpleChunkProvider.doRead(SimpleChunkProvider.java:91) 在 org.springframework.batch.core.step.item.SimpleChunkProvider.read(SimpleChunkProvider.java:157) 在 org.springframework.batch.core.step.item.SimpleChunkProvider $ 1.doInIteration(SimpleChunkProvider.java:116) 在 org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:374) 在 org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:215) 在 org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:144) 在 org.springframework.batch.core.step.item.SimpleChunkProvider.provide(SimpleChunkProvider.java:110) 在 org.springframework.batch.core.step.item.ChunkOrientedTasklet.execute(ChunkOrientedTasklet.java:69) 在 org.springframework.batch.core.step.tasklet.TaskletStep $ ChunkTransactionCallback.doInTransaction(TaskletStep.java:406) 在 org.springframework.batch.core.step.tasklet.TaskletStep $ ChunkTransactionCallback.doInTransaction(TaskletStep.java:330) 在 org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:133) 在 org.springframework.batch.core.step.tasklet.TaskletStep $ 2.doInChunkContext(TaskletStep.java:272) 在 org.springframework.batch.core.scope.context.StepContextRepeatCallback.doInIteration(StepContextRepeatCallback.java:81) 在 org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:374) 在 org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:215) 在 org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:144) 在 org.springframework.batch.core.step.tasklet.TaskletStep.doExecute(TaskletStep.java:257) 在 org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:200) 在 org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:148) 在 org.springframework.batch.core.job.flow.JobFlowExecutor.executeStep(JobFlowExecutor.java:64) 在 org.springframework.batch.core.job.flow.support.state.StepState.handle(StepState.java:67) 在 org.springframework.batch.core.job.flow.support.SimpleFlow.resume(SimpleFlow.java:169) 在 org.springframework.batch.core.job.flow.support.SimpleFlow.start(SimpleFlow.java:144) 在 org.springframework.batch.core.job.flow.FlowJob.doExecute(FlowJob.java:134) 在 org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:306) 在 org.springframework.batch.core.launch.support.SimpleJobLauncher $ 1.run(SimpleJobLauncher.java:135) 在 org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:50) 在 org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:128) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 在 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 在java.lang.reflect.Method.invoke(Method.java:498)at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:333) 在 org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190) 在 org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) 在 org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration $ PassthruAdvice.invoke(SimpleBatchConfiguration.java:127) 在 org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) 在 org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213) 在com.sun.proxy。$ Proxy244.run(未知来源)
答案 0 :(得分:0)
返回HibernateCursorItemReader
而非ItemReader
StepScope需要特定的实施类型。