繁体   English   中英

获取java.lang.IllegalStateException:无法在Spring Batch中执行CommandLineRunner

[英]Getting java.lang.IllegalStateException: Failed to execute CommandLineRunner in Spring Batch

当我尝试运行spring批处理时,出现以下错误。

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

码:

@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();
}

}

@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;
}

}

@Component
public class QueryBatchTasklet implements Tasklet{

@Autowired
private QueryBatchService autoClosureService;


@Override
public RepeatStatus execute(StepContribution stepContribution, ChunkContext chunkContext) throws Exception {

    autoClosureService.updateStatusAndTriggerComm();
    return null;
}

}

@Component
public class ClosureBatchTasklet implements Tasklet{

@Autowired
private ClosureBatchService closureBatchService;

@Override
public RepeatStatus execute(StepContribution stepContribution, ChunkContext chunkContext) throws Exception {

    closureBatchService.updateStatusAndTriggerComm();
    return null;
}

}

我突然有这个错误。 检查是否有在您连接到的数据库中的记录BATCH_JOB_INSTANCE不具有的匹配记录表BATCH_JOB_EXECUTION表。 也许Spring批处理元数据表中存在其他数据不一致的情况。 如果可能,请拖放并重新创建它们。

对于我们来说,此错误是由于数据库清除作业未能删除所需的一切而导致的。

请参阅我对这个类似问题的回答 ,可能会有帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM