检索spring-batch作业bean定义

时间:2015-12-22 10:22:51

标签: spring spring-batch

有没有办法检索在此位置声明的作业bean: classpath * / META-INF / spring / batch / jobs / * .xml

尝试下面的代码,但我无法检索它们。

  @Autowired
  private ApplicationContext applicationContext;

  public void sometMethod() {

      AutowireCapableBeanFactory beanFactory = applicationContext.getAutowireCapableBeanFactory();
      String[] strings = ((BeanDefinitionRegistry) beanFactory).getBeanDefinitionNames();

  }

1 个答案:

答案 0 :(得分:0)

我能够通过以下更改合并applicationContext和作业bean定义:

      @Autowired
      private ApplicationContext applicationContext;

      public void sometMethod() {

          ConfigurableApplicationContext context = new ClassPathXmlApplicationContext(new String[] {"classpath:META-INF/spring/batch/jobs/*.xml"}, applicationContext); 
          AutowireCapableBeanFactory beanFactory = context.getAutowireCapableBeanFactory();
          String[] strings = ((BeanDefinitionRegistry) beanFactory).getBeanDefinitionNames();

      }