【问题标题】:JUnit test with @SpringApplicationConfiguration start automatically the Job使用 @SpringApplicationConfiguration 的 JUnit 测试自动启动 Job
【发布时间】:2016-05-15 11:47:26
【问题描述】:

我正在为 Spring Boot 批处理编写 Junit 测试。 在我的 JUnit 中,我想启动一个步骤:

JobExecution jobExecution = jobLauncherTestUtils.launchStep("y");

我的 JUnit 类是用这些注释的:

@SpringApplicationConfiguration(classes = { MyBatchConfiguration.class })
@RunWith(SpringJUnit4ClassRunner.class)

我的问题是,即使测试方法中没有任何内容,测试也会启动我所有的批处理作业,因为它是以正常方式启动的。 这是我的 BatchConfFile 上的注释

@Configuration
@EnableBatchProcessing
@EnableAutoConfiguration
@ConditionalOnClass({ JobLauncher.class })
@ComponentScan({ "toto" })

和我的测试自动启动的作业:(

@Bean
public Job MyJob(@Qualifier("x") Step x, 
@Qualifier("y") Step y) {

        return jobs.get("j").incrementer(new DateJobIncrementer()).start(x).next(y).build();
    }

【问题讨论】:

    标签: java testing junit spring-boot spring-batch


    【解决方案1】:

    只需使用此内容创建src/test/resources/application.properties 文件:

    spring.batch.job.enabled=false # Do not execute all Spring Batch jobs in the context on startup.
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-07-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-22
      • 2012-08-17
      • 2011-04-17
      • 1970-01-01
      相关资源
      最近更新 更多