Friday, March 13, 2009

Classpath Scanning: Hidden Spring Gems

Class path scanning is not a trivial task in Java. There is no standard way to do it.
Fortunately, Spring framework can help here, as it does in many other aspects. It has an option for implicitly detecting the candidate components by scanning the classpath and matching it against the filters. But all you can do with standard Spring configuration is auto-creation of a  bunch of beans and possbly autowire them to some other bean.
What if you don't want to create beans, but just want to find specific classes and create their instances later? This can be accomplished by using ClassPathScanningCandidateComponentProvider - class that provides magic behind the Spring's class path scanning. Using it I created a simple utility class which can be used as a basis for your specific class scaners:

Here the example of specific class scanner to load classes inherited from JComponent and marked with @PreferencePage annotation:

Now we have a very powerful tool, which gives us plug in-like abilities. The program can scan the class path for specific services or GUI components and if they are present - load them. Even thaw this solution does not go as far as real plug in framework, it still allows for a greater degree of decoupling in your application.


  1. The Sports Betting phase accounts for the biggest market share and is estimated to develop at a CAGR of 12.5% over the forecast period. The means around this is to have a foreign checking 코인카지노 account, which has no such restrictions. It is perfectly authorized that you simply can} switch money out of your Korean checking account to a foreign checking account to a web-based pockets that Pokerstars accepts. There are not any particular laws prohibiting on-line gambling or poker in Korea. While could be} room for debate, most view poker as greater than only a game of likelihood.