【问题标题】:Could not autowire. No beans of 'JobRepositoryTestUtils' type found无法自动接线。找不到“JobRepositoryTestUtils”类型的 bean
【发布时间】:2021-07-02 03:23:35
【问题描述】:

我正在尝试使用 Spring Batch 为应用程序编写测试。 我以网站上的例子为基础Testing a Spring Batch Job

//@RunWith(SpringRunner.class)
@ExtendWith(SpringExtension.class)
//@SpringBatchTest
@SpringBootTest
@EnableAutoConfiguration
@ContextConfiguration(classes = { BatchConfig.class })
@TestExecutionListeners({ DependencyInjectionTestExecutionListener.class, DirtiesContextTestExecutionListener.class })
@DirtiesContext(classMode = ClassMode.AFTER_CLASS)
public class SpringBatchTest {

  @Autowired
  private JobLauncherTestUtils jobLauncherTestUtils;

  @Autowired
  private JobRepositoryTestUtils jobRepositoryTestUtils;

  @After
  public void cleanUp() {
    jobRepositoryTestUtils.removeJobExecutions();
  }
...
}

但是我在 bean jobRepositoryTestUtils 上有一个错误: 无法自动接线。找不到“JobRepositoryTestUtils”类型的 bean

【问题讨论】:

    标签: spring-batch


    【解决方案1】:

    您正在测试类中自动装配JobLauncherTestUtils,因此我假设在您的测试上下文中定义了该类型的bean(即BatchConfig.class)。 @SpringBatchTest 注解是自动添加的,但是你好像评论了这个注解。

    因此,您要么需要使用@SpringBatchTest(取消注释),要么在测试上下文中手动定义JobLauncherTestUtils bean。

    【讨论】:

      猜你喜欢
      • 2021-08-18
      • 2021-01-17
      • 2019-08-17
      • 2020-08-31
      • 2013-01-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多