Spring Batch配置NoSuchMethodError异常

时间:2013-07-26 12:38:01

标签: java spring spring-batch nosuchmethoderror

这是我第一次使用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();
  }

有关此问题的任何线索?

编辑:我正在使用

  • spring-core 3.2.2.RELEASE
  • spring-batch 2.2.0.RELEASE
  • spring-batch-infrastructure 2.2.0.RELEASE
  • spring-test 3.2.2.RELEASE

1 个答案:

答案 0 :(得分:0)

我遇到了同样的错误,我的解决方案是从我的依赖项中删除该版本,它运行正常。

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