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 閱讀(622) 評論(0)  編輯  收藏 所屬分類: SRPING BATCH

          主站蜘蛛池模板: 新野县| 盘锦市| 宁武县| 舟山市| 浦东新区| 枣强县| 肇东市| 和政县| 沅江市| 元阳县| 伊宁县| 河北省| 朔州市| 迁安市| 永靖县| 循化| 巴林右旗| 凉城县| 军事| 六枝特区| 许昌县| 陈巴尔虎旗| 通化市| 大名县| 城固县| 湖北省| 焉耆| 嘉义市| 丰顺县| 巴楚县| 马鞍山市| 杂多县| 金寨县| 彭州市| 略阳县| 扎囊县| 灵台县| 出国| 肃北| 延安市| 仁布县|