2

I have next spring batch configuration class:

@Configuration
@EnableBatchProcessing
public class BatchJobConfiguration {

    @Autowired
    private JobBuilderFactory jobBuilderFactory;

    @Autowired
    private StepBuilderFactory stepBuilderFactory;

    @Bean
    public Step step1() {
        return stepBuilderFactory.get("step1")
                .tasklet(new Tasklet() {
                    public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) {
                        return null;
                    }
                })
                .build();
    }

    @Bean
    public Job job(Step step1) throws Exception {
        return jobBuilderFactory.get("job1")
                .incrementer(new RunIdIncrementer())
                .start(step1)
                .build();
    }
}

When I start my application I receive next exception:

Caused by: java.lang.ClassCastException: org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean$$EnhancerBySpringCGLIB$$65a19538 cannot be cast to org.springframework.batch.core.repository.JobRepository at org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration$$EnhancerBySpringCGLIB$$14f7a80d.jobRepository() at org.springframework.batch.core.configuration.annotation.AbstractBatchConfiguration.jobBuilders(AbstractBatchConfiguration.java:58) at org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration$$EnhancerBySpringCGLIB$$14f7a80d.CGLIB$jobBuilders$6() at org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration$$EnhancerBySpringCGLIB$$14f7a80d$$FastClassBySpringCGLIB$$c6b630d7.invoke() at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:312) at org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration$$EnhancerBySpringCGLIB$$14f7a80d.jobBuilders() at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)

In pom.xml I have next dependency:

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

Thanks in advance.

4
  • Do you have any JpaRepositoryFactoryBean variable anywhere in your code? If you do, please post that line. Commented Aug 19, 2015 at 19:33
  • No, I don't have such variable. Commented Aug 19, 2015 at 19:35
  • Sorry I was inattentive. I found JobRepository interface which extend JpaRepository (SpringData). So I rename JobRepository and everything becomes okay. Please answer on my question and I'll close my post. Commented Aug 19, 2015 at 20:14
  • I was hoping that you will find something, otherwise this would have been a huge mistery for a long time. :) Commented Aug 19, 2015 at 20:20

1 Answer 1

4

The JobRepository instance needs to be renamed, otherwise Spring context will find incorrect candidates for autowiring.

Sign up to request clarification or add additional context in comments.

4 Comments

This is amazing. I had the similar issue and I also able to solved by renaming JobRepository. Thanks guys.
@GergelyBasco Would be good if you can elaborate on how to rename the JobRepository instance..
@Jimmycan you guide how you have renamed JobRepository
I see no reference to JobRepository instance so where did you rename it and rename to what?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.