Spring: specify all beans of type Foo

I know that in Spring you can load all beans of a specific type with:

ClassPathResource res = new ClassPathResource("spring_foo.xml"); XmlBeanFactory factory = new XmlBeanFactory(res); Map<String, Foo> beans = factory.getBeansOfType(Foo.class); 

How can I do this in XML? For instance. sort of:

 <bean id="fooHandler" class="com.mycompany.FooHandler"> <property name="foos"> <map beanType="com.mycompany.Foo" / > </property> </bean> 

Or is it better with a list rather than a map?

+4
source share
1 answer

Use the Java Configuration , which allows you to use Java to create beans. You can mix it with existing XML configuration files. See My answer on Spring 3.0.x - context: component scan to list result

+1
source

All Articles