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

          主站蜘蛛池模板: 崇礼县| 芒康县| 湄潭县| 南木林县| 吉隆县| 集贤县| 阳西县| 玉林市| 澜沧| 泾阳县| 湟源县| 古田县| 泗阳县| 新丰县| 华亭县| 江城| 高陵县| 金堂县| 赤水市| 启东市| 天峨县| 和林格尔县| 称多县| 宣威市| 靖西县| 二连浩特市| 肥西县| 温州市| 清河县| 柞水县| 孙吴县| 阳春市| 临夏市| 柳江县| 红桥区| 濮阳市| 楚雄市| 海安县| 进贤县| 梁山县| 福建省|