I want to scan all the classes in a package that that are subclasses of the particular class. Then I want to take these classes and for each of them instantiate a bean of same type, using the class as a property. Then I want to gather all these anonymous beans and put them into collection. Is it possible to configure spring context in XML like this? Thx
A:
In Java you can't list all classes that are contained in a package without direct access to the location where the class files are stored (usually the filesystem).
For the second part of your question have a look at spring-list-beans-by-type.
tangens
2009-10-07 15:08:09
A:
Probably the best way for you to implement this would be to write your own implementation of the Spring FactoryBean interface, and do all the introspection / reflection and scanning in that implementation to generate the end bean that you want put in the Spring applicationContext.
Alex Marshall
2009-10-07 18:36:23