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

          主站蜘蛛池模板: 稷山县| 卢龙县| 沧州市| 双鸭山市| 万年县| 平山县| 临沂市| 视频| 建阳市| 河源市| 麻江县| 承德市| 寿宁县| 东丰县| 资源县| 仪陇县| 六枝特区| 怀集县| 临沂市| 紫云| 白河县| 衡东县| 辉县市| 北票市| 逊克县| 天峨县| 门源| 凌云县| 盘锦市| 邯郸县| 郁南县| 通州市| 泸西县| 兴宁市| 浪卡子县| 达拉特旗| 通州区| 孝义市| 淮滨县| 河池市| 钟山县|