0
votes

This is the first time I am using Spring batch and I have an exception :

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)

I don't know how to solve this error. I am using a Java configuration to define the job, the step, the reader, the processor and the writer :

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

Any clues to how this problem?

EDIT : I am using

  • 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
Are all of your spring jars from the same version? NoSuchMethodError is suspicious.enl8enmentnow
I finally resolve my problems. Missing jarsDimitri

1 Answers

0
votes

I got this same error, the solution for me was removing the version from my dependency and it worked fine.

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