Najważniejsze jest to, że struktura testowa Spring Batch (v2) ma JobLauncherTestUtils.setJob
z adnotacją @Autowired
. Nasz zestaw testów ma wielu dostawców klasy Job
. Ponieważ ta klasa nie jest czymś, co mogę zmodyfikować, nie jestem pewna, w jaki sposób mogę zakwalifikować się do tego, z którą robotą zostanie wykonana autopsja, która może być inna w każdym teście.W jaki sposób mogę zakwalifikować program ustawiający, który nie jest "właścicielem"?
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
Próbowałem dodanie tego JavaConfig który jest rozpoznawany, ale błąd mówi, że nadal autocalling setJob
@Configuration
public class SpringTestConfiguration
{
@Bean
public JobLauncherTestUtils jobLauncherTestUtilsForSnapshot(final Job generateMetricsSnapshotJob)
{
JobLauncherTestUtils jobLauncherTestUtils = new JobLauncherTestUtils();
jobLauncherTestUtils.setJob(generateMetricsSnapshotJob);
return jobLauncherTestUtils;
}
}
notatka: Nie wymaga rozwiązania JavaConfig, ale byłoby miło . Chciałbym też, jeśli to możliwe, nadal Autowire pól takich jak JobRepository, ponieważ jest tylko jeden.
http://stackoverflow.com/q/22416140/206466 powiązane, może duplikować – xenoterracide