https://stackoverflow.com/questions/34217101/spring-batch-junit-test-for-multiple-jobs@Configuration
public class TestBatchConfiguration implements MergedBeanDefinitionPostProcessor {
@Autowired
@Qualifier("JobA")
private Job job;
@Bean(name="jtestl")
public JobLauncherTestUtils jobLauncherTestUtils() {
JobLauncherTestUtils jobLauncherTestUtils = new JobLauncherTestUtils();
jobLauncherTestUtils.setJob(job);
return jobLauncherTestUtils;
}
/**
* https://stackoverflow.com/questions/22416140/autowire-setter-override-with-java-config
* This is needed to inject the correct job into JobLauncherTestUtils
*/
@Override
public void postProcessMergedBeanDefinition(RootBeanDefinition beanDefinition, Class<?> beanType, String beanName) {
if(beanName.equals("jtestl")) {
beanDefinition.getPropertyValues().add("job", getMyBeanFirstAImpl());
}
}
private Object getMyBeanFirstAImpl() {
return job;
}
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
return bean;
}
@Override
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
return bean;
}
}