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 閱讀(1240) 評論(0)  編輯  收藏 所屬分類: SPRING

          主站蜘蛛池模板: 吉林市| 银川市| 武鸣县| 靖州| 扶绥县| 凤阳县| 乌什县| 类乌齐县| 桐城市| 疏勒县| 龙泉市| 松溪县| 黑水县| 类乌齐县| 读书| 石屏县| 班玛县| 金秀| 双流县| 镇平县| 兴山县| 潞城市| 新营市| 眉山市| 乡宁县| 静海县| 攀枝花市| 闽清县| 搜索| 蓬莱市| 且末县| 抚松县| 东兴市| 屏东县| 华安县| 当阳市| 湖南省| 中卫市| 高台县| 衡水市| 盐城市|