0

I need to read all beans of class com.Foo. How I used to do it:

BeanFactory factory = new XmlBeanFactory(new ClassPathResource(file));
Map elements = BeanFactoryUtils.beansOfTypeIncludingAncestors((ListableBeanFactory) factory, com.Foo.class);

It turns out that XmlBeanFactory is now deprecated. How do I read all beans of a given class in Spring 3.1 ?


edit: the new factory has to be able to load bean definition XML from any file, classpath or filesystem. Until now I used the Spring org.springframework.core.io.Resource interface and it worked pretty well (it has many implementations, for any kind of file)
Queequeg
  • 2,824
  • 8
  • 39
  • 66

1 Answers1

1

The class that takes Resource and resource locations as constructor argument is GenericXmlApplicationContext

From javadoc:

Convenient application context with built-in XML support. This is a flexible alternative to ClassPathXmlApplicationContext and FileSystemXmlApplicationContext, to be configured via setters, with an eventual refresh() call activating the context.

As for beansOfTypeIncludingAncestors() and ListableBeanFactory they are not deprecated.

Boris Treukhov
  • 17,493
  • 9
  • 70
  • 91