执行作业时遇到致命错误:org.springframework.dao.EmptyResultDataAccessException:结果大小不正确:预期为1,实际为0

问题描述 投票:0回答:2

我正在将 Spring boot/批处理代码从 1.4.0 升级到 2.7.2。迁移已完成,大部分代码正在运行。代码被部署到 JBOSS7/wildfly。

我在执行作业时遇到错误。

错误:

2022-08-30 08:16:04,280 INFO  [com.xyz.om.apm.batch.rest.ManualBatchTrigger] (default task-1) batchTrigger inside ManualBatchTrigger with date::: 20220714  ::::  triggered at::: Tue Aug 30 08:16:04 UTC 2022
2022-08-30 08:16:04,316 INFO  [org.springframework.batch.core.launch.support.SimpleJobLauncher] (default task-1) Job: [SimpleJob: [name=baseApplicationDataExtractorJob]] launched with the following parameters: [{JobID=1661847364286, date=1657756800000}]

2022-08-30 08:16:04,370 ERROR [org.springframework.batch.core.job.AbstractJob] (default task-1) Encountered fatal error executing job: org.springframework.dao.EmptyResultDataAccessException: Incorrect result size: expected 1, actual 0
    at org.springframework.dao.support.DataAccessUtils.nullableSingleResult(DataAccessUtils.java:97) [spring-tx-5.3.22.jar:5.3.22]
    at org.springframework.jdbc.core.JdbcTemplate.queryForObject(JdbcTemplate.java:880) [spring-jdbc-5.3.22.jar:5.3.22]
    at org.springframework.jdbc.core.JdbcTemplate.queryForObject(JdbcTemplate.java:906) [spring-jdbc-5.3.22.jar:5.3.22]
    at org.springframework.batch.core.repository.dao.JdbcJobExecutionDao.synchronizeStatus(JdbcJobExecutionDao.java:307) [spring-batch-core-4.3.6.jar:4.3.6]
    at org.springframework.batch.core.repository.support.SimpleJobRepository.update(SimpleJobRepository.java:174) [spring-batch-core-4.3.6.jar:4.3.6]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.8.0_332]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) [rt.jar:1.8.0_332]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.8.0_332]
    at java.lang.reflect.Method.invoke(Method.java:498) [rt.jar:1.8.0_332]
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344) [spring-aop-5.3.22.jar:5.3.22]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198) [spring-aop-5.3.22.jar:5.3.22]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) [spring-aop-5.3.22.jar:5.3.22]
    at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:123) [spring-tx-5.3.22.jar:5.3.22]
    at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:388) [spring-tx-5.3.22.jar:5.3.22]
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:119) [spring-tx-5.3.22.jar:5.3.22]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) [spring-aop-5.3.22.jar:5.3.22]
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:215) [spring-aop-5.3.22.jar:5.3.22]
    at com.sun.proxy.$Proxy127.update(Unknown Source)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.8.0_332]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) [rt.jar:1.8.0_332]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.8.0_332]
    at java.lang.reflect.Method.invoke(Method.java:498) [rt.jar:1.8.0_332]
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344) [spring-aop-5.3.22.jar:5.3.22]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198) [spring-aop-5.3.22.jar:5.3.22]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) [spring-aop-5.3.22.jar:5.3.22]
    at org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration$PassthruAdvice.invoke(SimpleBatchConfiguration.java:128) [spring-batch-core-4.3.6.jar:4.3.6]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) [spring-aop-5.3.22.jar:5.3.22]
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:215) [spring-aop-5.3.22.jar:5.3.22]
    at com.sun.proxy.$Proxy127.update(Unknown Source)
    at org.springframework.batch.core.job.AbstractJob.updateStatus(AbstractJob.java:443) [spring-batch-core-4.3.6.jar:4.3.6]
    at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:315) [spring-batch-core-4.3.6.jar:4.3.6]
    at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:149) [spring-batch-core-4.3.6.jar:4.3.6]
    at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:50) [spring-core-5.3.22.jar:5.3.22]
    at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:140) [spring-batch-core-4.3.6.jar:4.3.6]
    at com.xyz.om.apm.batch.rest.ManualBatchTrigger.batchTrigger(ManualBatchTrigger.java:147) [classes:]
    at com.xyz.om.apm.batch.rest.ManualBatchTrigger$$FastClassBySpringCGLIB$$5c65fdc.invoke(<generated>) [classes:]
    at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) [spring-core-5.3.22.jar:5.3.22]
    

2022-08-30 08:16:04,382 INFO  [org.springframework.batch.core.launch.support.SimpleJobLauncher] (default task-1) Job: [SimpleJob: [name=baseApplicationDataExtractorJob]] failed unexpectedly and fatally with the following parameters: [{JobID=1661847364286, date=1657756800000}]: org.springframework.dao.EmptyResultDataAccessException: Incorrect result size: expected 1, actual 0
    at org.springframework.dao.support.DataAccessUtils.nullableSingleResult(DataAccessUtils.java:97) [spring-tx-5.3.22.jar:5.3.22]
    at org.springframework.jdbc.core.JdbcTemplate.queryForObject(JdbcTemplate.java:880) [spring-jdbc-5.3.22.jar:5.3.22]
    at org.springframework.jdbc.core.JdbcTemplate.queryForObject(JdbcTemplate.java:906) [spring-jdbc-5.3.22.jar:5.3.22]
    at org.springframework.batch.core.repository.dao.JdbcJobExecutionDao.synchronizeStatus(JdbcJobExecutionDao.java:307) [spring-batch-core-4.3.6.jar:4.3.6]
    at org.springframework.batch.core.repository.support.SimpleJobRepository.update(SimpleJobRepository.java:174) [spring-batch-core-4.3.6.jar:4.3.6]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.8.0_332]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) [rt.jar:1.8.0_332]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.8.0_332]
    at java.lang.reflect.Method.invoke(Method.java:498) [rt.jar:1.8.0_332]
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344) [spring-aop-5.3.22.jar:5.3.22]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198) [spring-aop-5.3.22.jar:5.3.22]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) [spring-aop-5.3.22.jar:5.3.22]
    at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:123) [spring-tx-5.3.22.jar:5.3.22]
    at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:388) [spring-tx-5.3.22.jar:5.3.22]
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:119) [spring-tx-5.3.22.jar:5.3.22]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) [spring-aop-5.3.22.jar:5.3.22]
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:215) [spring-aop-5.3.22.jar:5.3.22]
    at com.sun.proxy.$Proxy127.update(Unknown Source)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.8.0_332]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) [rt.jar:1.8.0_332]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.8.0_332]
    at java.lang.reflect.Method.invoke(Method.java:498) [rt.jar:1.8.0_332]
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344) [spring-aop-5.3.22.jar:5.3.22]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198) [spring-aop-5.3.22.jar:5.3.22]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) [spring-aop-5.3.22.jar:5.3.22]
    at org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration$PassthruAdvice.invoke(SimpleBatchConfiguration.java:128) [spring-batch-core-4.3.6.jar:4.3.6]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) [spring-aop-5.3.22.jar:5.3.22]
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:215) [spring-aop-5.3.22.jar:5.3.22]
    at com.sun.proxy.$Proxy127.update(Unknown Source)
    at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:378) [spring-batch-core-4.3.6.jar:4.3.6]
    at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:149) [spring-batch-core-4.3.6.jar:4.3.6]
    at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:50) [spring-core-5.3.22.jar:5.3.22]
    at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:140) [spring-batch-core-4.3.6.jar:4.3.6]
    at com.xyz.om.apm.batch.rest.ManualBatchTrigger.batchTrigger(ManualBatchTrigger.java:147) [classes:]
    at com.xyz.om.apm.batch.rest.ManualBatchTrigger$$FastClassBySpringCGLIB$$5c65fdc.invoke(<generated>) [classes:]

我无法理解这里的问题。

代码:

@RestController
@RequestMapping("/rest")
public class ManualBatchTrigger {
    
    private final static Logger logger = LoggerFactory.getLogger(ManualBatchTrigger.class);
    
    @Autowired
    private Environment environment;
    @Autowired
    private SimpleJobLauncher jobLauncher;
    @Autowired
    private Step baseApplicationDataExtractorStep;
    @Autowired
    private Job baseApplicationDataExtractorJob;
    @Autowired
    private FTSUtils ftsUtils;

@RequestMapping(value = "/triggerbatch/{date}", method = RequestMethod.GET)
    public String batchTrigger(@PathVariable String date) throws ParseException {

        logger.info("batchTrigger inside ManualBatchTrigger with date::: " + date + "  ::::  triggered at::: " + new Date());

        DateFormat format = new SimpleDateFormat("yyyyMMdd");

        JobExecution execution = null;
        try {
            JobParameters param = new JobParametersBuilder()
                    .addString("JobID", String.valueOf(System.currentTimeMillis()))
                    .addDate("date", format.parse(date))
                    .toJobParameters();

            execution = jobLauncher.run(baseApplicationDataExtractorJob(baseApplicationDataExtractorStep), param);
        } catch(Exception e) {
            logger.error("@@ Error in Manual Batch Trigger  2@@  :  ", e);
            e.printStackTrace();
        }
        
        if(execution != null) {
            logger.info("execution != null");
            logger.info("Job finished with status :" + execution.getStatus());
            return execution.getStatus().toString();
        }           
        return "Job Failed!";
    }

    private Job baseApplicationDataExtractorJob(Step baseApplicationDataExtractorStep2) {
        return baseApplicationDataExtractorJob;
    }

错误出现在这一行: 我已经用 google 搜索了该错误 100 次,但该错误与所提出的任何解决方案/查询无关。

execution = jobLauncher.run(baseApplicationDataExtractorJob(baseApplicationDataExtractorStep), param);

**完整错误堆栈:** https://drive.google.com/file/d/1p5didOTbMO3OE-qCAJYR-h9Cfrc79-TV/view?usp=sharing

java spring spring-boot spring-batch
2个回答
0
投票

问题确实与SpringBoot的更新有关。 迁移指南建议首先迁移到最新的SpringBoot 1.5,然后再迁移到2.0、2.1、2.2等。

我在这里遇到的这个特定错误与内部bean有关,例如MapJobRepositoryFactoryBean和其他在您浏览SpringBoot版本(以及spring-core)时被弃用和删除的bean。

在迁移过程中,您可以通过在每个弃用注释中将已弃用的类替换为推荐的类来解决问题。


-2
投票

就我而言,问题出在 spring.datasource.hikari.auto-commit=false 中。将其更改为 true 后,它就起作用了。

© www.soinside.com 2019 - 2024. All rights reserved.