paulwong

          Spring Batch JUnit test for multiple jobs


          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;
              }
          }

          posted on 2019-07-31 10:48 paulwong 閱讀(628) 評(píng)論(0)  編輯  收藏 所屬分類(lèi): SRPING BATCH

          主站蜘蛛池模板: 托克托县| 甘泉县| 花莲县| 吐鲁番市| 平阳县| 浏阳市| 贵溪市| 静宁县| 老河口市| 西平县| 宝应县| 湖州市| 抚顺市| 大悟县| 天门市| 襄樊市| 沙洋县| 海阳市| 九江县| 敦化市| 南汇区| 慈溪市| 寿阳县| 盐池县| 桑植县| 灵宝市| 山西省| 共和县| 防城港市| 汪清县| 富顺县| 汉沽区| 日土县| 双鸭山市| 景东| 天全县| 叶城县| 崇信县| 延长县| 惠水县| 合作市|