2015-12-22 77 views
0

有沒有辦法檢索在此位置聲明的作業bean:classpath */META-INF/spring/batch/jobs/*。xml檢索彈簧批處理作業bean定義

試過下面的代碼,但我無法檢索它們。

@Autowired 
    private ApplicationContext applicationContext; 

    public void sometMethod() { 

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

    } 
+0

的可能的複製http://stackoverflow.com/questions/16769941/spring-method -to-GET-全豆期的一所賜型 –

回答

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(); 

     }