Spring batch 无法自动连线。没有';JobRepositoryTestUtils';找到的类型

Spring batch 无法自动连线。没有';JobRepositoryTestUtils';找到的类型,spring-batch,Spring Batch,我正在尝试使用SpringBatch为应用程序编写测试。 我以网站上的例子为基础 但是我在bean jobRepositoryTestUtils上有一个错误: 无法自动连线。找不到“JobRepositoryTestUtils”类型的bean您正在测试类中自动连接JobLauncherTestUtils,因此我假设在测试上下文中定义了该类型的bean(即BatchConfig.class)。@SpringBatchTest注释会自动添加它,但您似乎已经对该注释进行了注释 因此,您需要在测试上下文

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

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

您正在测试类中自动连接
JobLauncherTestUtils
,因此我假设在测试上下文中定义了该类型的bean(即
BatchConfig.class
)。
@SpringBatchTest
注释会自动添加它,但您似乎已经对该注释进行了注释

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

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