这是我的配置文件:
@Configuration
@EnableBatchProcessing
@Import(DatasourceConfig.class)
public class BatchProcessConfiguration {
@Autowired
public JobBuilderFactory jobBuilderFactory;
@Autowired
public StepBuilderFactory stepBuilderFactory;
@Autowired
public DriverManagerDataSource dataSource;
@Bean
MapJobRepositoryFactoryBean jobRepository() {
MapJobRepositoryFactoryBean mjRFBean = new MapJobRepositoryFactoryBean();
mjRFBean.setTransactionManager(transactionManager());
return mjRFBean;
}
@Bean
SimpleJobLauncher jobLauncher() throws Exception {
SimpleJobLauncher jobLauncher = new SimpleJobLauncher();
JobRepository jobRepo = jobRepository().getJobRepository();
jobLauncher.setJobRepository(jobRepo);
return jobLauncher;
}
@Bean
JdbcCursorItemReader<MyDto> databaseItemReader() {
JdbcCursorItemReader<MyDto> jdbcItemReader = new JdbcCursorItemReader<MyDto>();
jdbcItemReader.setDataSource(dataSource);
jdbcItemReader.setSql(QUERY);
jdbcItemReader.setRowMapper(new ControparteRowMapper());
return jdbcItemReader;
}
@Bean
FlatFileItemWriter<MyDto> fileItemWriter() {
...
}
...
@Bean
MyListener jobListener() {
return new MyListener();
}
@Bean
MyProcessor itemProcessor() {
return new MyProcessor();
}
ResourcelessTransactionManager transactionManager() {
return new ResourcelessTransactionManager();
}
@Bean
public Job myJob(MyJobListener listener) {
...
}
@Bean
public Step step1() {
...
}
我有这个错误:
Exception in thread "main" org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'batchProcessConfiguration': Unsatisfied dependency expressed through field 'jobBuilderFactory';
nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'jobBuilders' defined in class path resource [org/springframework/batch/core/configuration/annotation/SimpleBatchConfiguration.class]:
Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException:
Failed to instantiate [org.springframework.batch.core.configuration.annotation.JobBuilderFactory]: Factory method 'jobBuilders' threw exception; nested exception is java.lang.ClassCastException:
org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean$$EnhancerBySpringCGLIB$$2bfb173 cannot be cast to org.springframework.batch.core.repository.JobRepository
我的配置有什么问题?
感谢。