StoredProcedureItemReader 无法重试 java.sql.SQLTimeoutException

StoredProcedureItemReader not able to retry on java.sql.SQLTimeoutException

我很难让我的 StoredProcedureItemReader 在由于 SQLTimeoutException 而失败后重试。 这是我的步骤过程的配置:

@Bean    
public Step Step() throws Exception {       
            return stepBuilderFactory.get("Step")
                    .<Student, Student>chunk(100)
                    .reader(storedProcItemReader())
                    .processor(studentItemProcessor)
                    .writer(fileItemWriter())
                    .faultTolerant()
                    .retryLimit(5)
                    .retry(QueryTimeoutException.class)
                    .retry(SQLTimeoutException.class)
                    .backOffPolicy(backoffPolicy())
                    .build();
    }

    @Bean
    @StepScope
    public RetryableItemReader<Student> storedProcItemReader() throws Exception {
        return studentItemReader.getDataFromDatabase(dataSource);
    }

studentItemReader class 文件:

@Component
@StepScope
public class studentItemReader{

    public RetryableItemReader<Student> getDataFromDatabase(DataSource dataSource) {
        
RetryTemplate retryTemplate = RetryTemplate.builder()
                .maxAttempts(5)
                .exponentialBackoff(1000, 2, 20000)
                .retryOn(QueryTimeoutException.class)
                .retryOn(SQLTimeoutException.class)
                .build();

            StoredProcedureItemReader<RegionResponse> reader = new StoredProcedureItemReader<>();
            
            SqlParameter[] parameter = { new SqlParameter("@studentId",
                    java.sql.Types.INTEGER) };
            PreparedStatementSetter statementValues = new PreparedStatementSetter() {
                @Override
                public void setValues(PreparedStatement ps) throws SQLException {
                    ps.setInt(1, parameterValue);
                    }
            };
            reader.setDataSource(dataSource);
            reader.setProcedureName("dbo.StudentReport");
            reader.setParameters(parameter);
            reader.setPreparedStatementSetter(statementValues);
            reader.setRowMapper(new StudentRowMapper());
            reader.setQueryTimeout(1500);
            return new RetryableItemReader<>(reader, retryTemplate);
        }   
    }
}

重试:

import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.item.ItemStreamException;
import org.springframework.batch.item.ItemStreamReader;
import org.springframework.batch.item.database.StoredProcedureItemReader;
import org.springframework.retry.support.RetryTemplate;

public class RetryableItemReader<T> implements ItemStreamReader<T> {

    private final StoredProcedureItemReader<T> delegate;
    private final RetryTemplate retryTemplate;

    public RetryableItemReader(StoredProcedureItemReader<T> delegate, RetryTemplate retryTemplate) {
        this.delegate = delegate;
        this.retryTemplate = retryTemplate;
    }

    @Override
    public T read() throws Exception {
        return retryTemplate.execute(context -> delegate.read());
    }

    @Override
    public void open(ExecutionContext executionContext) throws ItemStreamException {
        delegate.open(executionContext);
    }

    @Override
    public void update(ExecutionContext executionContext) throws ItemStreamException {
        delegate.update(executionContext);
    }

    @Override
    public void close() throws ItemStreamException {
        delegate.close();
    }
}

我在无法重试的日志中看到:

2021-09-09 19:21:10.405 [SimpleAsyncTaskExecutor-4] WARN  c.z.hikari.pool.ProxyConnection:182      - HikariPool-1 - Connection ConnectionID:4 ClientConnectionId: bf81d056-0bc4-4657-b201-bc638d128f13 marked as broken because of SQLSTATE(HY008), ErrorCode(0)
java.sql.SQLTimeoutException: The query has timed out.
    at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:226)
    at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.execute(SQLServerPreparedStatement.java:505)
    at com.zaxxer.hikari.pool.ProxyPreparedStatement.execute(ProxyPreparedStatement.java:44)
    at com.zaxxer.hikari.pool.HikariProxyCallableStatement.execute(HikariProxyCallableStatement.java)
    at org.springframework.batch.item.database.StoredProcedureItemReader.openCursor(StoredProcedureItemReader.java:213)
    at org.springframework.batch.item.database.AbstractCursorItemReader.doOpen(AbstractCursorItemReader.java:428)
    at org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader.open(AbstractItemCountingItemStreamItemReader.java:150)
    at gov.va.med.ccrs.pit.extract.retry.RetryableItemReader.open(RetryableItemReader.java:25)
    at gov.va.med.ccrs.pit.extract.retry.RetryableItemReader$$FastClassBySpringCGLIB$ad4b84a.invoke(<generated>)
    at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:771)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:749)
    at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:136)
    at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:124)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:749)
    at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:691)
    at gov.va.med.ccrs.pit.extract.retry.RetryableItemReader$$EnhancerBySpringCGLIB$$a742dbe0.open(<generated>)
    at org.springframework.batch.item.support.CompositeItemStream.open(CompositeItemStream.java:103)
    at org.springframework.batch.core.step.item.ChunkMonitor.open(ChunkMonitor.java:114)
    at org.springframework.batch.item.support.CompositeItemStream.open(CompositeItemStream.java:103)
    at org.springframework.batch.core.step.tasklet.TaskletStep.open(TaskletStep.java:311)
    at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:205)
    at org.springframework.batch.core.partition.support.TaskExecutorPartitionHandler.call(TaskExecutorPartitionHandler.java:138)
    at org.springframework.batch.core.partition.support.TaskExecutorPartitionHandler.call(TaskExecutorPartitionHandler.java:135)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at java.base/java.lang.Thread.run(Thread.java:834)
2021-09-09 19:21:10.406 [SimpleAsyncTaskExecutor-3] DEBUG o.s.retry.support.RetryTemplate:324      - Retry: count=0
2021-09-09 19:21:10.406 [SimpleAsyncTaskExecutor-3] DEBUG o.s.retry.support.RetryTemplate:324      - Retry: count=0
2021-09-09 19:21:10.408 [SimpleAsyncTaskExecutor-3] DEBUG o.s.retry.support.RetryTemplate:324      - Retry: count=0
2021-09-09 19:21:10.522 [SimpleAsyncTaskExecutor-1] ERROR o.s.batch.core.step.AbstractStep:237     - Encountered an error executing step slaveStep in job Pit-Extract
org.springframework.batch.item.ItemStreamException: Failed to initialize the reader
    at org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader.open(AbstractItemCountingItemStreamItemReader.java:153)
    at gov.va.med.ccrs.pit.extract.retry.RetryableItemReader.open(RetryableItemReader.java:25)
    at gov.va.med.ccrs.pit.extract.retry.RetryableItemReader$$FastClassBySpringCGLIB$ad4b84a.invoke(<generated>)
    at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:771)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:749)
    at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:136)
    at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:124)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:749)
    at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:691)
    at gov.va.med.ccrs.pit.extract.retry.RetryableItemReader$$EnhancerBySpringCGLIB$$a742dbe0.open(<generated>)
    at org.springframework.batch.item.support.CompositeItemStream.open(CompositeItemStream.java:103)
    at org.springframework.batch.core.step.item.ChunkMonitor.open(ChunkMonitor.java:114)
    at org.springframework.batch.item.support.CompositeItemStream.open(CompositeItemStream.java:103)
    at org.springframework.batch.core.step.tasklet.TaskletStep.open(TaskletStep.java:311)
    at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:205)
    at org.springframework.batch.core.partition.support.TaskExecutorPartitionHandler.call(TaskExecutorPartitionHandler.java:138)
    at org.springframework.batch.core.partition.support.TaskExecutorPartitionHandler.call(TaskExecutorPartitionHandler.java:135)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: org.springframework.dao.QueryTimeoutException: Executing stored procedure; SQL [{call dbo.StudentReport(?)}]; The query has timed out.; nested exception is java.sql.SQLTimeoutException: The query has timed out.
    at org.springframework.jdbc.support.SQLExceptionSubclassTranslator.doTranslate(SQLExceptionSubclassTranslator.java:76)
    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72)
    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81)
    at org.springframework.batch.item.database.StoredProcedureItemReader.openCursor(StoredProcedureItemReader.java:229)
    at org.springframework.batch.item.database.AbstractCursorItemReader.doOpen(AbstractCursorItemReader.java:428)
    at org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader.open(AbstractItemCountingItemStreamItemReader.java:150)
    ... 21 common frames omitted
Caused by: java.sql.SQLTimeoutException: The query has timed out.
    at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:226)
    at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.execute(SQLServerPreparedStatement.java:505)
    at com.zaxxer.hikari.pool.ProxyPreparedStatement.execute(ProxyPreparedStatement.java:44)
    at com.zaxxer.hikari.pool.HikariProxyCallableStatement.execute(HikariProxyCallableStatement.java)
    at org.springframework.batch.item.database.StoredProcedureItemReader.openCursor(StoredProcedureItemReader.java:213)
    ... 23 common frames omitted
2021-09-09 19:21:10.522 [SimpleAsyncTaskExecutor-4] ERROR o.s.batch.core.step.AbstractStep:237     - Encountered an error executing step slaveStep in job Pit-Extract
org.springframework.batch.item.ItemStreamException: Failed to initialize the reader
    at org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader.open(AbstractItemCountingItemStreamItemReader.java:153)
    at gov.va.med.ccrs.pit.extract.retry.RetryableItemReader.open(RetryableItemReader.java:25)
    at gov.va.med.ccrs.pit.extract.retry.RetryableItemReader$$FastClassBySpringCGLIB$ad4b84a.invoke(<generated>)
    at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:771)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:749)
    at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:136)
    at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:124)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:749)
    at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:691)
    at gov.va.med.ccrs.pit.extract.retry.RetryableItemReader$$EnhancerBySpringCGLIB$$a742dbe0.open(<generated>)
    at org.springframework.batch.item.support.CompositeItemStream.open(CompositeItemStream.java:103)
    at org.springframework.batch.core.step.item.ChunkMonitor.open(ChunkMonitor.java:114)
    at org.springframework.batch.item.support.CompositeItemStream.open(CompositeItemStream.java:103)
    at org.springframework.batch.core.step.tasklet.TaskletStep.open(TaskletStep.java:311)
    at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:205)
    at org.springframework.batch.core.partition.support.TaskExecutorPartitionHandler.call(TaskExecutorPartitionHandler.java:138)
    at org.springframework.batch.core.partition.support.TaskExecutorPartitionHandler.call(TaskExecutorPartitionHandler.java:135)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: org.springframework.dao.QueryTimeoutException: Executing stored procedure; SQL [{call dbo.StudentReport(?)}]; The query has timed out.; nested exception is java.sql.SQLTimeoutException: The query has timed out.
    at org.springframework.jdbc.support.SQLExceptionSubclassTranslator.doTranslate(SQLExceptionSubclassTranslator.java:76)
    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72)
    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81)
    at org.springframework.batch.item.database.StoredProcedureItemReader.openCursor(StoredProcedureItemReader.java:229)
    at org.springframework.batch.item.database.AbstractCursorItemReader.doOpen(AbstractCursorItemReader.java:428)
    at org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader.open(AbstractItemCountingItemStreamItemReader.java:150)
    ... 21 common frames omitted
Caused by: java.sql.SQLTimeoutException: The query has timed out.
    at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:226)
    at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.execute(SQLServerPreparedStatement.java:505)
    at com.zaxxer.hikari.pool.ProxyPreparedStatement.execute(ProxyPreparedStatement.java:44)
    at com.zaxxer.hikari.pool.HikariProxyCallableStatement.execute(HikariProxyCallableStatement.java)
    at org.springframework.batch.item.database.StoredProcedureItemReader.openCursor(StoredProcedureItemReader.java:213)
    ... 23 common frames omitted
2021-09-09 19:21:10.582 [SimpleAsyncTaskExecutor-2] WARN  c.z.hikari.pool.ProxyConnection:182      - HikariPool-1 - Connection ConnectionID:5 ClientConnectionId: 161fd25b-5a39-465c-b1a6-8116952b1972 marked as broken because of SQLSTATE(HY008), ErrorCode(0)
java.sql.SQLTimeoutException: The query has timed out.
    at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:226)
    at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.execute(SQLServerPreparedStatement.java:505)
    at com.zaxxer.hikari.pool.ProxyPreparedStatement.execute(ProxyPreparedStatement.java:44)
    at com.zaxxer.hikari.pool.HikariProxyCallableStatement.execute(HikariProxyCallableStatement.java)
    at org.springframework.batch.item.database.StoredProcedureItemReader.openCursor(StoredProcedureItemReader.java:213)
    at org.springframework.batch.item.database.AbstractCursorItemReader.doOpen(AbstractCursorItemReader.java:428)
    at org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader.open(AbstractItemCountingItemStreamItemReader.java:150)
    at gov.va.med.ccrs.pit.extract.retry.RetryableItemReader.open(RetryableItemReader.java:25)
    at gov.va.med.ccrs.pit.extract.retry.RetryableItemReader$$FastClassBySpringCGLIB$ad4b84a.invoke(<generated>)
    at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:771)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:749)
    at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:136)
    at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:124)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:749)
    at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:691)
    at gov.va.med.ccrs.pit.extract.retry.RetryableItemReader$$EnhancerBySpringCGLIB$$a742dbe0.open(<generated>)
    at org.springframework.batch.item.support.CompositeItemStream.open(CompositeItemStream.java:103)
    at org.springframework.batch.core.step.item.ChunkMonitor.open(ChunkMonitor.java:114)
    at org.springframework.batch.item.support.CompositeItemStream.open(CompositeItemStream.java:103)
    at org.springframework.batch.core.step.tasklet.TaskletStep.open(TaskletStep.java:311)
    at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:205)
    at org.springframework.batch.core.partition.support.TaskExecutorPartitionHandler.call(TaskExecutorPartitionHandler.java:138)
    at org.springframework.batch.core.partition.support.TaskExecutorPartitionHandler.call(TaskExecutorPartitionHandler.java:135)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at java.base/java.lang.Thread.run(Thread.java:834)
2021-09-09 19:21:10.583 [SimpleAsyncTaskExecutor-2] ERROR o.s.batch.core.step.AbstractStep:237     - Encountered an error executing step slaveStep in job Pit-Extract
org.springframework.batch.item.ItemStreamException: Failed to initialize the reader
    at org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader.open(AbstractItemCountingItemStreamItemReader.java:153)
    at gov.va.med.ccrs.pit.extract.retry.RetryableItemReader.open(RetryableItemReader.java:25)
    at gov.va.med.ccrs.pit.extract.retry.RetryableItemReader$$FastClassBySpringCGLIB$ad4b84a.invoke(<generated>)
    at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:771)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:749)
    at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:136)
    at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:124)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:749)
    at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:691)
    at gov.va.med.ccrs.pit.extract.retry.RetryableItemReader$$EnhancerBySpringCGLIB$$a742dbe0.open(<generated>)
    at org.springframework.batch.item.support.CompositeItemStream.open(CompositeItemStream.java:103)
    at org.springframework.batch.core.step.item.ChunkMonitor.open(ChunkMonitor.java:114)
    at org.springframework.batch.item.support.CompositeItemStream.open(CompositeItemStream.java:103)
    at org.springframework.batch.core.step.tasklet.TaskletStep.open(TaskletStep.java:311)
    at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:205)
    at org.springframework.batch.core.partition.support.TaskExecutorPartitionHandler.call(TaskExecutorPartitionHandler.java:138)
    at org.springframework.batch.core.partition.support.TaskExecutorPartitionHandler.call(TaskExecutorPartitionHandler.java:135)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: org.springframework.dao.QueryTimeoutException: Executing stored procedure; SQL [{call dbo.StudentReport(?)}]; The query has timed out.; nested exception is java.sql.SQLTimeoutException: The query has timed out.
    at org.springframework.jdbc.support.SQLExceptionSubclassTranslator.doTranslate(SQLExceptionSubclassTranslator.java:76)
    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72)
    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81)
    at org.springframework.batch.item.database.StoredProcedureItemReader.openCursor(StoredProcedureItemReader.java:229)
    at org.springframework.batch.item.database.AbstractCursorItemReader.doOpen(AbstractCursorItemReader.java:428)
    at org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader.open(AbstractItemCountingItemStreamItemReader.java:150)
    ... 21 common frames omitted
Caused by: java.sql.SQLTimeoutException: The query has timed out.
    at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:226)
    at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.execute(SQLServerPreparedStatement.java:505)
    at com.zaxxer.hikari.pool.ProxyPreparedStatement.execute(ProxyPreparedStatement.java:44)
    at com.zaxxer.hikari.pool.HikariProxyCallableStatement.execute(HikariProxyCallableStatement.java)
    at org.springframework.batch.item.database.StoredProcedureItemReader.openCursor(StoredProcedureItemReader.java:213)
    ... 23 common frames omitted
2021-09-09 19:21:12.888 [custom-executor1] ERROR o.s.batch.core.step.AbstractStep:237     - Encountered an error executing step masterStep in job Student-Info-Extract
org.springframework.batch.core.JobExecutionException: Partition handler returned an unsuccessful step
    at org.springframework.batch.core.partition.support.PartitionStep.doExecute(PartitionStep.java:112)
    at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:208)
    at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:148)
    at org.springframework.batch.core.job.flow.JobFlowExecutor.executeStep(JobFlowExecutor.java:68)
    at org.springframework.batch.core.job.flow.support.state.StepState.handle(StepState.java:68)
    at org.springframework.batch.core.job.flow.support.SimpleFlow.resume(SimpleFlow.java:169)
    at org.springframework.batch.core.job.flow.support.SimpleFlow.start(SimpleFlow.java:144)
    at org.springframework.batch.core.job.flow.FlowJob.doExecute(FlowJob.java:137)
    at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:319)
    at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:147)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at java.base/java.lang.Thread.run(Thread.java:834)

请告诉我我在这里犯了什么错误。提前致谢!

您的 RetryableItemReader 仅重试 read 操作,但在初始化 reader 时发生超时,即在 open 方法中。这可以在这里看到:

org.springframework.batch.item.ItemStreamException: Failed to initialize the reader
    at org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader.open(AbstractItemCountingItemStreamItemReader.java:153)
    at gov.va.med.ccrs.pit.extract.retry.RetryableItemReader.open(RetryableItemReader.java:25)
...

此方法未在您的 RetryableItemReader 中重试。您可以像 read 方法一样使其可重试,例如:

@Override
public void open(ExecutionContext executionContext) throws ItemStreamException {
    retryTemplate.execute(new RetryCallback<Object, ItemStreamException>() {
        @Override
        public Object doWithRetry(RetryContext retryContext) throws ItemStreamException {
            delegate.open(executionContext);
            return null;
        };
    });
}

也就是说,我会调查为什么会发生超时,因为在读取实际数据时它可能会再次发生(即使重试)。