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

          主站蜘蛛池模板: 咸阳市| 阿合奇县| 石河子市| 龙井市| 灵台县| 千阳县| 阳城县| 洛南县| 大厂| 湘潭市| 蓝田县| 云龙县| 陕西省| 绥江县| 田林县| 汨罗市| 铁岭市| 沽源县| 陇川县| 彭州市| 林周县| 治县。| 海城市| 城固县| 东兴市| 柘荣县| 都安| 龙泉市| 白水县| 天台县| 鹤山市| 乳源| 南陵县| 嘉鱼县| 澎湖县| 塘沽区| 平遥县| 鄂伦春自治旗| 白朗县| 石河子市| 舒兰市|