tags:

views:

419

answers:

3

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
A: 

The closest thing that sounds like what you're asking for is the <context:component-scan> pattern (see docs here), but what you're asking for is highly specific, and to be honest, doesn't make much sense. If you could give a concrete example, it would help a lot.

skaffman
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