这是我第一次使用 Spring 批处理,但有一个例外:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'stepScope' defined in class path resource [org/springframework/batch/core/configuration/annotation/StepScopeConfiguration.class]: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.springframework.batch.core.scope.StepScope org.springframework.batch.core.configuration.annotation.StepScopeConfiguration.stepScope()] threw exception; nested exception is java.lang.NoSuchMethodError: org.springframework.batch.core.scope.StepScope.setAutoProxy(Z)V
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:581)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1031)
....
Caused by: java.lang.NoSuchMethodError: org.springframework.batch.core.scope.StepScope.setAutoProxy(Z)V
at org.springframework.batch.core.configuration.annotation.StepScopeConfiguration.stepScope(AbstractBatchConfiguration.java:130)
我不知道如何解决这个错误。我正在使用 Java 配置来定义作业、步骤、读取器、处理器和写入器:
public class SpringBatchTestJobConfig extends PersistenceSpringConfig {
@Autowired
private JobBuilderFactory jobBuilders;
@Autowired
private StepBuilderFactory stepBuilders;
@Bean
@StepScope
public FlatFileItemReader<EntiteJuridique> cvsReader(@Value("#{jobParameters[input.file]}") String input)
{
log.info("cvsReader");
FlatFileItemReader<EntiteJuridique> flatFileReader = new FlatFileItemReader<EntiteJuridique>();
flatFileReader.setLineMapper(lineMapper());
flatFileReader.setResource(new ClassPathResource(input));
return flatFileReader;
}
@Bean
public ItemWriter<EntiteJuridiqueJPA> writer()
{
log.info("writer");
JpaItemWriter<EntiteJuridiqueJPA> jpaWriter = new JpaItemWriter<EntiteJuridiqueJPA>();
try
{
jpaWriter.setEntityManagerFactory(entityManagerFactory().nativeEntityManagerFactory);
}
catch (Exception exception)
{
log.debug(exception);
}
return jpaWriter;
}
@Bean
public Job dataInitializer()
{
return jobBuilders.get("dataInitializer").start(step()).build();
}
@Bean
public Step step()
{
return stepBuilders.get("step").<EntiteJuridique, EntiteJuridiqueJPA> chunk(1).reader(cvsReader(null)).processor(processor())
.writer(writer()).build();
}
有什么线索可以解决这个问题吗?
编辑:我正在使用
- 弹簧核心 3.2.2.RELEASE
- spring-batch 2.2.0.RELEASE
- spring-batch-infrastructure 2.2.0.RELEASE
- 弹簧测试 3.2.2.RELEASE