I have a launch-context.xml that defines 7 different jobs, all of which have the same parent. They have names like "jobA", "jobB" and so on.
I tried:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "/launch-context.xml", "/OurBatchKernelTestConfig.xml" })
public class AllTest extends BaseRaptorBatchTest {
@Autowired
private JobLauncherTestUtils utils;
@Autowired
@Qualifier(value="jobA")
private Job job;
@Test
public void testLaunch() {
Properties p = new Properties(); // then I set these up.
JobExecution je = utils.launchJob(paraCvter.getJobParameters(p));
}
}
This does not work.
I get an exception like:
STDOUT [WARN ] [2015.04.15 11:14:42] support.GenericApplicationContext - Exception encountered during context initialization - cancelling refresh attempt
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jobLauncherTestUtilsForSnapshot': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void org.springframework.batch.test.JobLauncherTestUtils.setJob(org.springframework.batch.core.Job); nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [org.springframework.batch.core.Job] is defined: expected single matching bean but found 2: coverageRuleBatch,generateMetricsSnapshotJob
I also tried:
https://stackoverflow.com/a/29658577/869809
and I tried:
https://stackoverflow.com/a/36352437/869809
Neither of these work.
I can create a copy of my launch-content.xml and remove the other jobs. Then I refer to that in the annotation and all is good. But I then need 7 different xml files. Ick.