修改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
相关产品推荐
相关产品推荐

