The bottom line is that the Spring Batch (v2) test framework has JobLauncherTestUtils.setJob with the @Autowired annotation. There are several Job class providers in our test suite. Since this class is not something that I can change, I'm not sure how I can qualify which task it gets automatically, which may be different for each test.
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 tried adding this JavaConfig that was recognized, but the error says it is still auto- setJob
@Configuration public class SpringTestConfiguration { @Bean public JobLauncherTestUtils jobLauncherTestUtilsForSnapshot( final Job generateMetricsSnapshotJob ) { JobLauncherTestUtils jobLauncherTestUtils = new JobLauncherTestUtils(); jobLauncherTestUtils.setJob( generateMetricsSnapshotJob ); return jobLauncherTestUtils; } }
note: I don't need a JavaConfig solution, but it would be nice. Also, I would like, if possible, to still use Autowire fields such as JobRepository, since there is only one.
java spring spring-batch spring-java-config spring-3
xenoterracide
source share