Spring Batch哪个配置会运行?

时间:2018-05-22 21:43:19

标签: spring-batch

在我简单的Spring Batch应用程序中,我有一个配置......

@Configuration
public class StepTransitionConfiguration {
    @Autowired
    private JobBuilderFactory jobBuilderFactory;

    @Autowired
    private StepBuilderFactory stepBuilderFactory;


    @Bean
    public Step step1() {
        ...
    }

    @Bean
    public Step step2() {
        ...
    }

    @Bean
    public Job transitionJobSimpleNext() {
            return jobBuilderFactory.get("transitionJobNext")
                    .start(step1())
                    .next(step2())
                    .build();
    }

唯一的其他课程是

@SpringBootApplication
@EnableBatchProcessing
public class TransitionsApplication {
    public static void main(String[] args) {
        SpringApplication.run(TransitionsApplication.class, args);
    }
}

所以我开始考虑Application类如何知道批处理使用该特定配置。所以我添加了另一个配置......

@Configuration
public class AnotherTransitionConfiguration {
    @Autowired
    private JobBuilderFactory jobBuilderFactory;

    @Autowired
    private StepBuilderFactory stepBuilderFactory;


    @Bean
    public Step step4() {
        ...
    }

    @Bean
    public Step step5() {
        ...
    }

    @Bean
    public Job transitionJobSimpleNext() {
            return jobBuilderFactory.get("transitionJobNext")
                    .start(step4())
                    .next(step5())
                    .build();
    }

现在,当我运行应用程序时,它总是使用第二个配置,即使它们都在类路径上。这是为什么?

0 个答案:

没有答案