paulwong

PathMatchingResourcePatternResolver

通常如果要查找文件,是用的File再传入一个绝对路径,如果要找WEB下面的就不方便了。SPRING有个好用的Resolver:PathMatchingResourcePatternResolver。

PathMatchingResourcePatternResolver是一个通配符的Resource查找器,包括:
/WEB-INF/*-context.xml
com/mycompany/**/applicationContext.xml
file:C:/some/path/*-context.xml
classpath:com/mycompany/**/applicationContext.xml

如果要处理一个目录下的文件就可以下面的代码: 
ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
        
Resource[] resources = resolver.getResources("classpath:com/you/atlas/webx/context/*.class");
        
System.out.println(resources[0].getURL());
File file = resources[0].getFile();
echo:file:/home/work/branche/springtest/target/classes/com/you/atlas/webx/context/WebxContextLoader.class

posted on 2012-12-15 19:47 paulwong 阅读(1217) 评论(0)  编辑  收藏 所属分类: SPRING


只有注册用户登录后才能发表评论。


网站导航: