Dienstag, 25. November 2008

Spring: Get Classpath Resources with Wildcards

With Spring's Resource abstraction it is easy to load resources from the classpath, but what if you need to load many files that follow a certain naming pattern? The following code accomplishes that with the org.springframework.core.io.support.PathMatchingResourcePatternResolver, it supports the same wildcards in the URL like the ApplicationContextLoader:

PathMatchingResourcePatternResolver patternResolver = new PathMatchingResourcePatternResolver();
Resource[] resources = patternResolver.getResources("classpath:/conf/aggregations/*_agg.xml");