IndexOutOfBoundsException 春季批处理和春季启动

Posted

技术标签:

【中文标题】IndexOutOfBoundsException 春季批处理和春季启动【英文标题】:IndexOutOfBoundsException spring batch and spring boot 【发布时间】:2017-10-06 20:24:56 【问题描述】:

我有 Spring Boot 和 Spring Batch 项目。 我正在使用弹簧批处理

<dependency>
    <groupId>org.springframework.batch</groupId>
    <artifactId>spring-batch-core</artifactId>
    <version>3.0.7.RELEASE</version>
</dependency>

和弹簧靴 1.3.5 运行项目时出现此异常:

2017-05-08 19:33:28.363 DEBUG 23790 --- [           main] o.s.w.c.s.StandardServletEnvironment     : Adding [server.ports] PropertySource with highest search precedence
2017-05-08 19:33:28.372  INFO 23790 --- [           main] o.s.b.a.b.JobLauncherCommandLineRunner   : Running default command line with: [--debug, --spring.output.ansi.enabled=always]
2017-05-08 19:33:28.399 ERROR 23790 --- [           main] o.s.boot.SpringApplication               : Application startup failed

java.lang.IllegalStateException: Failed to execute CommandLineRunner
    at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:809) [spring-boot-1.3.5.RELEASE.jar:1.3.5.RELEASE]
    at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:790) [spring-boot-1.3.5.RELEASE.jar:1.3.5.RELEASE]
    at org.springframework.boot.SpringApplication.afterRefresh(SpringApplication.java:777) [spring-boot-1.3.5.RELEASE.jar:1.3.5.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:308) [spring-boot-1.3.5.RELEASE.jar:1.3.5.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1191) [spring-boot-1.3.5.RELEASE.jar:1.3.5.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1180) [spring-boot-1.3.5.RELEASE.jar:1.3.5.RELEASE]
    at com.sellware.module.ebay.Application.main(Application.java:52) [classes/:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_121]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_121]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_121]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_121]
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144) [idea_rt.jar:na]
Caused by: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
    at java.util.ArrayList.rangeCheck(ArrayList.java:653) ~[na:1.8.0_121]
    at java.util.ArrayList.get(ArrayList.java:429) ~[na:1.8.0_121]
    at org.springframework.boot.autoconfigure.batch.JobLauncherCommandLineRunner.getNextJobParameters(JobLauncherCommandLineRunner.java:145) ~[spring-boot-autoconfigure-1.3.5.RELEASE.jar:1.3.5.RELEASE]
    at org.springframework.boot.autoconfigure.batch.JobLauncherCommandLineRunner.execute(JobLauncherCommandLineRunner.java:214) ~[spring-boot-autoconfigure-1.3.5.RELEASE.jar:1.3.5.RELEASE]
    at org.springframework.boot.autoconfigure.batch.JobLauncherCommandLineRunner.executeLocalJobs(JobLauncherCommandLineRunner.java:233) ~[spring-boot-autoconfigure-1.3.5.RELEASE.jar:1.3.5.RELEASE]
    at org.springframework.boot.autoconfigure.batch.JobLauncherCommandLineRunner.launchJobFromProperties(JobLauncherCommandLineRunner.java:125) ~[spring-boot-autoconfigure-1.3.5.RELEASE.jar:1.3.5.RELEASE]
    at org.springframework.boot.autoconfigure.batch.JobLauncherCommandLineRunner.run(JobLauncherCommandLineRunner.java:119) ~[spring-boot-autoconfigure-1.3.5.RELEASE.jar:1.3.5.RELEASE]
    at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:806) [spring-boot-1.3.5.RELEASE.jar:1.3.5.RELEASE]
    ... 11 common frames omitted

【问题讨论】:

【参考方案1】:

通过排除 BatchAutoConfiguration 解决

@SpringBootApplication(exclude = BatchAutoConfiguration.class)

【讨论】:

但是这会阻止应用程序运行任何批处理作业。 我已经在 XML 配置文件中实现了 Spring Batch 所需 Bean 的初始化,并且它正在工作,因为我在 Spring Batch 作业中进行了许多自定义我在 xml 中声明的 Bean 是( JobRepositoryFactoryBean、MapJobRegistry、JobExplorerFactoryBean、JobRegistryBeanPostProcessor、SimpleJobOperator ) 哦,好的。不使用注解时,我对 Spring 不熟悉。

以上是关于IndexOutOfBoundsException 春季批处理和春季启动的主要内容,如果未能解决你的问题,请参考以下文章

java.lang.IndexOutOfBoundsException:源不适合目标

ListView IndexOutOfBoundsException

IndexOutOfBoundsException 没有被抛出 JFrame

在索引处添加到 ArrayList 时出现 IndexOutOfBoundsException

RecyclerView:检测到 IndexOutOfBoundsException 不一致。无效的项目位置

ArrayIndexOutOfBoundsException 和 IndexOutOfBoundsException 之间的区别?