title: Getting java.lang.IllegalStateException: Failed to execute CommandLineRunner in Spring Batch
body: <p>I am getting the below error when I try to run a spring batch.</p>
  
  <pre><code>java.lang.IllegalStateException: Failed to execute CommandLineRunner
  at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:779) ~[spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
  at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:760) ~[spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
  at org.springframework.boot.SpringApplication.afterRefresh(SpringApplication.java:747) ~[spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
  at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) ~[spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
  at com.amhi.care.claims.query.batch.QueryBatchApplication.main(QueryBatchApplication.java:15) [classes/:na]
  
  
  Caused by: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
  at java.util.ArrayList.rangeCheck(ArrayList.java:657) ~[na:1.8.0_192]
  at java.util.ArrayList.get(ArrayList.java:433) ~[na:1.8.0_192]
  at org.springframework.boot.autoconfigure.batch.JobLauncherCommandLineRunner.getNextJobParameters(JobLauncherCommandLineRunner.java:143) ~[spring-boot-autoconfigure-1.5.3.RELEASE.jar:1.5.3.RELEASE]
  at org.springframework.boot.autoconfigure.batch.JobLauncherCommandLineRunner.execute(JobLauncherCommandLineRunner.java:212) ~[spring-boot-autoconfigure-1.5.3.RELEASE.jar:1.5.3.RELEASE]
  at org.springframework.boot.autoconfigure.batch.JobLauncherCommandLineRunner.executeLocalJobs(JobLauncherCommandLineRunner.java:231) ~[spring-boot-autoconfigure-1.5.3.RELEASE.jar:1.5.3.RELEASE]
  at org.springframework.boot.autoconfigure.batch.JobLauncherCommandLineRunner.launchJobFromProperties(JobLauncherCommandLineRunner.java:123) ~[spring-boot-autoconfigure-1.5.3.RELEASE.jar:1.5.3.RELEASE]
  at org.springframework.boot.autoconfigure.batch.JobLauncherCommandLineRunner.run(JobLauncherCommandLineRunner.java:117) ~[spring-boot-autoconfigure-1.5.3.RELEASE.jar:1.5.3.RELEASE]
  at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:776) ~[spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
  ... 4 common frames omitted
  </code></pre>
  
  <p>Code:</p>
  
  <pre><code>@Configuration
  @EnableBatchProcessing
  @EnableScheduling
  @EnableTransactionManagement
  @ComponentScan(QueryBatchConstants.COMPONENT_SCAN_PACKAGE)
  @Import(DataSourcecConfiguration.class)
  public class QueryBatchConfiguration {
  
  @Autowired
  public JobBuilderFactory jobBuilderFactory;
  
  @Autowired
  public StepBuilderFactory stepBuilderFactory;
  
  
  @Bean
  public Job reminderJob() {
      return jobBuilderFactory.get("reminderJob").flow(step()).next(closureStep()).end().build();
  }
  
  @Bean
  public Step step() {
      return stepBuilderFactory.get("step").tasklet(tasklet()).build();
  }
  @Bean
  public Step closureStep() {     
      return stepBuilderFactory.get("closureStep").tasklet(closureTasklet()).build();
  }
  
  @Bean
  public Tasklet tasklet(){
      return new QueryBatchTasklet();
  }
  
  @Bean
  public Tasklet closureTasklet(){
      return new ClosureBatchTasklet();
  }
  
  
  @Bean 
  @JobScope
  public JobParameters jobParamater(){
      return new JobParametersBuilder()
              .addDate("date", new Date())
              .toJobParameters();
  }
  
  /**
   * This method is used to configure the Dozer Mapper
   * 
   * @return Mapper
   * @throws IOException
   */
  @Bean(name = "mapper")
  public Mapper configDozerMapper() throws IOException {
  
  DozerBeanMapper mapper = new DozerBeanMapper();
  return mapper;
  }
  
  /**
   * This method is used to create RIDC client manager
   * 
   * @return IdcClientManager
   */
  @Bean(name = "idcClientmanager")
  public IdcClientManager idcClientmanager() {
  return new IdcClientManager();
  }
  </code></pre>
  
  <p>}</p>
  
  <pre><code>@Configuration
  @EnableTransactionManagement
  @ComponentScan(QueryBatchConstants.COMPONENT_SCAN_PACKAGE)
  @PropertySource(QueryBatchConstants.CLASSPATH_APPLICATION_PROPERTIES)
  public class DataSourcecConfiguration {
  
  @Resource
  private Environment env;
  
  @Autowired
  public DataSource dataSource;
  
    /**
   * This method is used to configure a data source
   * 
   * @return DataSource
   * @throws SQLException
   */
  @Bean
  public DataSource dataSource() throws SQLException {
  DriverManagerDataSource dataSource = new DriverManagerDataSource();
  
  dataSource.setDriverClassName(env.getRequiredProperty(QueryBatchConstants.DATABASE_DRIVER));
  dataSource.setUrl(env.getRequiredProperty(QueryBatchConstants.DATABASE_URL));
  dataSource.setUsername(env.getRequiredProperty(QueryBatchConstants.DATABASE_USERNAME));
  dataSource.setPassword(env.getRequiredProperty(QueryBatchConstants.DATABASE_PSWRD));
  
  return dataSource;
  }
  
  /**
   * This method is used to configure a entity manager factory
   * 
   * @return LocalContainerEntityManagerFactoryBean
   * @throws SQLException
   */
  @Autowired
  @Bean
  public LocalContainerEntityManagerFactoryBean entityManagerFactory() throws SQLException {
  LocalContainerEntityManagerFactoryBean entityManager = new LocalContainerEntityManagerFactoryBean();
  entityManager.setDataSource(dataSource());
  entityManager.setPersistenceProviderClass(HibernatePersistence.class);
  entityManager.setPackagesToScan(env.getRequiredProperty(QueryBatchConstants.PACKAGES_TO_SCAN));
  entityManager.setJpaProperties(jpaProperties());
  
  return entityManager;
  }
  
  /**
   * This method is used to configure the JPA properties
   * 
   * @return JPA Properties
   */
  private Properties jpaProperties() {
  Properties properties = new Properties();
  properties.put(QueryBatchConstants.HIBERNATE_DIALECT, env.getRequiredProperty(QueryBatchConstants.HIBERNATE_DIALECT));
  properties.put(QueryBatchConstants.HIBERNATE_SHOW_SQL, env.getRequiredProperty(QueryBatchConstants.HIBERNATE_SHOW_SQL));
  properties.put(QueryBatchConstants.HIBERNATE_JDBC_META_DATA, env.getRequiredProperty(QueryBatchConstants.HIBERNATE_FALSE));
  return properties;
  }
  
  /**
   * This method is used to configure the transaction manager
   * 
   * @param emf
   * @return JpaTransactionManager
   */
  @Bean
  public JpaTransactionManager transactionManager(EntityManagerFactory emf) {
  JpaTransactionManager transactionManager = new JpaTransactionManager();
  transactionManager.setEntityManagerFactory(emf);
  
  return transactionManager;
  }
  
  @Bean
  public JdbcTemplate jdbcTemplate(DataSource dataSource) {
      JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
      jdbcTemplate.setResultsMapCaseInsensitive(true);
      return jdbcTemplate;
  }
  </code></pre>
  
  <p>}</p>
  
  <pre><code>@Component
  public class QueryBatchTasklet implements Tasklet{
  
  @Autowired
  private QueryBatchService autoClosureService;
  
  
  @Override
  public RepeatStatus execute(StepContribution stepContribution, ChunkContext chunkContext) throws Exception {
  
      autoClosureService.updateStatusAndTriggerComm();
      return null;
  }
  </code></pre>
  
  <p>}</p>
  
  <pre><code>@Component
  public class ClosureBatchTasklet implements Tasklet{
  
  @Autowired
  private ClosureBatchService closureBatchService;
  
  @Override
  public RepeatStatus execute(StepContribution stepContribution, ChunkContext chunkContext) throws Exception {
  
      closureBatchService.updateStatusAndTriggerComm();
      return null;
  }
  </code></pre>
  
  <p>}</p>