Ý chính là khung kiểm tra Lô mùa xuân (v2) có JobLauncherTestUtils.setJob
với chú thích @Autowired
. Bộ thử nghiệm của chúng tôi có nhiều nhà cung cấp lớp học Job
. Vì lớp này không phải là một cái gì đó tôi có thể sửa đổi, tôi không chắc chắn làm thế nào tôi có thể đủ điều kiện mà công việc nó được autowired với, mà có thể khác nhau cho mỗi thử nghiệm.Làm thế nào tôi có thể hội đủ điều kiện cho trình thiết lập tự động mà tôi không "sở hữu"
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
Tôi đã thử thêm JavaConfig này được công nhận, nhưng lỗi nói nó vẫn autocalling setJob
@Configuration
public class SpringTestConfiguration
{
@Bean
public JobLauncherTestUtils jobLauncherTestUtilsForSnapshot(final Job generateMetricsSnapshotJob)
{
JobLauncherTestUtils jobLauncherTestUtils = new JobLauncherTestUtils();
jobLauncherTestUtils.setJob(generateMetricsSnapshotJob);
return jobLauncherTestUtils;
}
}
lưu ý: Tôi không đòi hỏi một giải pháp JavaConfig, nhưng nó muốn được tốt đẹp . Ngoài ra, tôi muốn, nếu có thể, vẫn còn các trường Autowire như JobRepository, vì chỉ có một.
http://stackoverflow.com/q/22416140/206466 liên quan, có thể trùng lặp – xenoterracide