Spring Batch配置异常

时间:2015-08-19 18:44:13

标签: java spring spring-batch

我有下一个春季批量配置类:

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

当我启动我的应用程序时,我收到下一个异常:

  

引起:java.lang.ClassCastException:   org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean $$ EnhancerBySpringCGLIB $$ 65a19538   无法施展   org.springframework.batch.core.repository.JobRepository at   org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration $$ EnhancerBySpringCGLIB $$ 14f7a80d.jobRepository()     在   org.springframework.batch.core.configuration.annotation.AbstractBatchConfiguration.jobBuilders(AbstractBatchConfiguration.java:58)     在   org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration $$ EnhancerBySpringCGLIB $$ 14f7a80d.CGLIB $ jobBuilders $ 6()     在   org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration $$ EnhancerBySpringCGLIB $$ 14f7a80d $$ FastClassBySpringCGLIB $$ c6b630d7.invoke()     在   org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)     在   org.springframework.context.annotation.ConfigurationClassEnhancer $ BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:312)     在   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)     在   sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)     在java.lang.reflect.Method.invoke(Method.java:497)at   org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)

在pom.xml中我有下一个依赖:

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

提前致谢。

1 个答案:

答案 0 :(得分:3)

需要重命名JobRepository实例,否则Spring上下文会找到不正确的自动装配候选者。