我目前正在使用spring批处理的spring引导项目。我正尝试使用JavaConfig而不是xml,但对于当前所有的xml文档都很困难。Spring批处理Java配置JobLauncherTestUtils
我跟着https://blog.codecentric.de/en/2013/06/spring-batch-2-2-javaconfig-part-5-modular-configurations,但在使用JobLauncherTestUtils
时遇到困难。我知道我需要告诉测试使用正确的春天背景,但我似乎无法弄清楚如何去做。我得到以下错误:
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.batch.test.JobLauncherTestUtils' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
我的测试如下所示:
@RunWith(SpringRunner.class)
@SpringBootTest(classes = {MyApplication.class, MyJobConfiguration.class})
public class RetrieveDividendsTest {
@Autowired
private JobLauncherTestUtils jobLauncherTestUtils;
@Test
public void testSomething() throws Exception {
jobLauncherTestUtils.launchJob();
}
}
您是否曾尝试将TestExecutionListener注释添加到测试类以注入配置的应用程序上下文? '@TestExecutionListeners({的DependencyInjectionTestExecutionListener.class, })' 看一看http://docs.spring.io/spring-batch/reference/html/testing.html#testingIndividualSteps怎么看工作,如何在那里测试单个步骤。 –
@Sander_M但要做到这一点,我需要有'JobLauncherTestUtils'工作这是我的问题。我正在尝试进行端到端或个别步骤测试,而不仅仅是测试组件。 –