加载XML配置文件的BeanFactory的使用演示

public static void main(String[] args)
{
  DefaultListableBeanFactory beanRegistry=new DefaultListableBeanFactory();
  BeanFactory container=(BeanFactory)bindViaXMLFile(beanRegistry);
  
  FXNewsProvider newsProvider=(FXNewsProvider)container.getBean("djNewsProvider");
  newsProvider.getAndPersistNews();
}

public static BeanFactory bindViaXMLFile(BeanDefinitionRegistry registry)
{
  XmlBeanDefinitionReader reader=new XmlBeanDefinitionReader(registry);
  reader.loadBeanDefinitions("classpath:../news-config.xml");
  return (BeanFactory)registry;
 
  //或者直接
  //return new XmlBeanFactory(new ClassPathResource("../news-config.xml"));
}

 

posted @ 2012-06-26 15:26  来自非洲大草原的食人虎  阅读(409)  评论(0编辑  收藏  举报