You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

修改Spring Batch测试方法返回值后触发IllegalArgumentException异常求助

修改Spring Batch测试方法返回值后触发IllegalArgumentException异常求助

各位好,我最近在调整Spring Batch的测试代码时遇到了个棘手问题——把原本返回void的ingest方法改成返回JobExecution后,测试直接抛出了IllegalArgumentException,想请大家帮忙看看问题出在哪。

我做的代码修改如下:

-   protected void ingest(String filename) throws Exception {
+   protected JobExecution ingest(String filename) throws Exception {
        JobParameters jobParameters = new JobParametersBuilder().addString("input.file", filename).toJobParameters();
        JobExecution jobExecution = this.jobLauncherTestUtils.launchJob(jobParameters);
        Assertions.assertEquals(ExitStatus.COMPLETED, jobExecution.getExitStatus());
+       return jobExecution;
    }

修改后运行测试,直接抛出了如下异常信息:

java.lang.IllegalArgumentException: Could not create job execution from method: ingest
    at org.springframework.batch.test.JobScopeTestExecutionListener.getJobExecution(JobScopeTestExecutionListener.java:128)
    at org.springframework.batch.test.JobScopeTestExecutionListener.prepareTestInstance(JobScopeTestExecutionListener.java:77)
    at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:260)
    at org.springframework.test.context.junit.jupiter.SpringExtension.postProcessTestInstance(SpringExtension.java:163)
    at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
    at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:179)
    at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1708)
    at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
    at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
    at java.base/java.util.stream.StreamSpliterators$WrappingSpliterator.forEachRemaining(StreamSpliterators.java:310)
    at java.base/java.util.stream.Streams$ConcatSpliterator.forEachRemaining(Streams.java:735)
    at java.base/java.util.stream.Streams$ConcatSpliterator.forEachRemaining(Streams.java:734)
    at java.base/java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:762)
    at java.base/java.util.Optional.orElseGet(Optional.java:364)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
Caused by: java.lang.IllegalArgumentException: No matching arguments found for method: ingest
    at org.springframework.batch.item.adapter.HippyMethodInvoker.findMatchingMethod(HippyMethodInvoker.java:73)
    at org.springframework.util.MethodInvoker.prepare(MethodInvoker.java:190)
    at org.springframework.batch.test.JobScopeTestExecutionListener.getJobExecution(JobScopeTestExecutionListener.java:124)
    ... 15 more

备注:内容来源于stack exchange,提问作者wytten

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.17 12:14:32