日本免费精品_最新日韩一区_亚洲视频一区在线_a在线视频观看_天天射夜夜骑_粉嫩av一区二区三区_欧美中日韩免费视频_综合图区欧美_国内精品美女在线观看_午夜精品久久久久久久男人的天堂

首頁 > 學院 > 開發設計 > 正文

Spring4.3.x 淺析xml配置的解析過程(2)——使用ResourceLoader創建Resource對象

2019-11-10 20:14:05
字體:
來源:轉載
供稿:網友

概述


在走進xmlBeanDefinitionReader中已經講過XmlBeanDefinitionReader把xml配置信息轉換成一個一個的BeanDefinition對象的大致過程,在這個過程中還有幾個細節沒有講到,這一篇,就來探討其中一個細節——ResourceLoader如何根據指定的location生成Resource對象。

下面我們從XmlBeanDefinitionReader 使用xml配置文件地址加載BeanDefinition對象的入口loadBeanDefinitions(String location)方法開始。loadBeanDefinitions方法是XmlBeanDefinitionReader繼承自其父類AbstractBeanDefinitionReader。下面代碼是loadBeanDefinitions方法在AbstractBeanDefinitionReader類中的實現。

public int loadBeanDefinitions(String location) throws BeanDefinitionStoreException { return loadBeanDefinitions(location, null); } public int loadBeanDefinitions(String location, Set<Resource> actualResources) throws BeanDefinitionStoreException { ResourceLoader resourceLoader = getResourceLoader(); if (resourceLoader == null) { throw new BeanDefinitionStoreException( "Cannot import bean definitions from location [" + location + "]: no ResourceLoader available"); } if (resourceLoader instanceof ResourcePatternResolver) { // 使用資源模式解析器解析配置文件的路徑并加載資源 try { // 加載所有與指定location參數匹配的所有資源 Resource[] resources = ((ResourcePatternResolver) resourceLoader).getResources(location); // 加載指定的資源中的所有BeanDefinition int loadCount = loadBeanDefinitions(resources); if (actualResources != null) { for (Resource resource : resources) { actualResources.add(resource); } } if (logger.isDebugEnabled()) { logger.debug("Loaded " + loadCount + " bean definitions from location pattern [" + location + "]"); } return loadCount; } catch (IOException ex) { throw new BeanDefinitionStoreException( "Could not resolve bean definition resource pattern [" + location + "]", ex); } } else { // 直接加載資源且只加載一個資源,默認使用DefaultResourceLoader的getResource方法 Resource resource = resourceLoader.getResource(location); // 加載指定的resource中的所有BeanDefinition int loadCount = loadBeanDefinitions(resource); if (actualResources != null) { actualResources.add(resource); } if (logger.isDebugEnabled()) { logger.debug("Loaded " + loadCount + " bean definitions from location [" + location + "]"); } return loadCount; } }

SPRing提供了ResourceLoader接口用于加載不同的Resource對象,即將不同Resource對象的創建交給ResourceLoader來完成。Spring通過兩種方式加載資源,一種是根據具體的路徑加載一個資源,另一種方式通過模式匹配來加載多個資源。前者通過ResourceLoader的getResource(String location)方法實現,后者通過ResourceLoader子接口ResourcePatternResolver擴展的getResources(String locationPattern)方法實現。

上面的loadBeanDefinitions(String location, Set<Resource> actualResources)方法首先判斷當前持有的ResourceLoader的類型,如果實現了ResourcePatternResolver接口,則通過第二種方式加載資源,否則使用第一種方式加載一個資源, 下面通過spring源碼的分析來探討這兩個方法。

1 根據具體的路徑加載資源


在Spring中加載單個資源有個默認的實現,那就是DefaultResourceLoader的getResource(String location)方法,而XmlWebapplicationContext繼承了此方法,getResource方法的代碼如下。

/** * 根據指定location獲取第一個查找到的資源 */ public Resource getResource(String location) { Assert.notNull(location, "Location must not be null"); // 聲明有:String CLASSPATH_URL_PREFIX ="classpath:"; if (location.startsWith(CLASSPATH_URL_PREFIX)) { // 返回ClassPathResource對象 return new ClassPathResource(location.substring(CLASSPATH_URL_PREFIX.length()), getClassLoader()); } else { try { // 把location解析成URL對象 URL url = new URL(location); // 返回UrlResource對象 return new UrlResource(url); } catch (MalformedURLException ex) { // 給定的location是一個相對地址,即沒有前綴。 // ->把location解析為一個ClassPathContextResource return getResourceByPath(location); } } } @Override public Resource getResource(String location) { Assert.notNull(location, "Location must not be null"); // 首先使用ProtocolResolver來通過location參數創建Resource對象 // spring4.3開始才有的 for (ProtocolResolver protocolResolver : this.protocolResolvers) { Resource resource = protocolResolver.resolve(location, this); if (resource != null) { return resource; } } if (location.startsWith("/")) { return getResourceByPath(location); } else if (location.startsWith(CLASSPATH_URL_PREFIX)) { // 聲明有:String CLASSPATH_URL_PREFIX ="classpath:"; // 返回ClassPathResource對象 return new ClassPathResource(location.substring(CLASSPATH_URL_PREFIX.length()), getClassLoader()); } else { try { // 把location解析成URL對象 URL url = new URL(location); // 返回UrlResource對象 return new UrlResource(url); } catch (MalformedURLException ex) { // 給定的location是一個相對地址,即沒有前綴。 // ->默認把location解析為一個ClassPathContextResource return getResourceByPath(location); } } }

這段代碼處理三種類型的location:

第一種是以classpath:為前綴的,這種location參數直接返回一個ClassPathResource對象,表示加載classes路徑下的資源;

第二種是使用網絡協議作為前綴的,比如http、ftp等,這種直接返回一個UrlResource對象;

第三種是無前綴的,在默認實現中和第一種一樣是加載classes路徑下的資源,只是現在返回的對象是ClassPathContextResource對象,代碼如下。

/** * 根據指定路徑獲取資源。 * 返回的是一個ClassPathContextResource對象 */ protected Resource getResourceByPath(String path) { return new ClassPathContextResource(path, getClassLoader()); } /** * ClassPathContextResource 通過實現ContextResource,明確的指明了加載的文件是相對于上線文所在的路徑。 */ private static class ClassPathContextResource extends ClassPathResource implements ContextResource { public ClassPathContextResource(String path, ClassLoader classLoader) { super(path, classLoader); } public String getPathWithinContext() { return getPath(); } @Override public Resource createRelative(String relativePath) { String pathToUse = StringUtils.applyRelativePath(getPath(), relativePath); return new ClassPathContextResource(pathToUse, getClassLoader()); } }

XmlWebApplicationContext的父類AbstractRefreshableWebApplicationContext重寫了getResourceByPath(String path)方法,代碼如下。

@Override protected Resource getResourceByPath(String path) { return new ServletContextResource(this.servletContext, path); }

ServletContextResource代表的文件是相對于web容器根目錄的,通過它的下面一段代碼就一目了然了。

public InputStream getInputStream() throws IOException { InputStream is = this.servletContext.getResourceAsStream(this.path); if (is == null) { throw new FileNotFoundException("Could not open " + getDescription()); } return is; }

因此在web應用中,spring會把無前綴的location當成是web容器根目錄下的某個文件。

2 根據模式匹配加載多個資源


所謂的模式匹配也就是location參數使用了通配符,比如’*’、’?’等,在spring中,location參數為下面3中情況時,會加載多個資源 1. 使用ant風格的通配符 2. 以classpath*:為前綴 3. 以上兩種同用

Spring通過實現ResoureLoader的子接口ResourcePatternResolver來加載多個資源文件。其中,XmlWebApplicationContext實現了ResourcePatternResolver接口,而此接口的getResources(String locationPattern)方法已在XmlWebApplicationContext的父類AbstractApplicationContext中實現了,代碼如下。

public Resource[] getResources(String locationPattern) throws IOException { // 把獲取資源的實現委托給其他ResourcePatternResolver,默認為PathMatchingResourcePatternResolver return this.resourcePatternResolver.getResources(locationPattern); }

這段代碼把加載指定模式的資源的任務委托給PathMatchingResourcePatternResolver的getResources(String locationPattern)方法,這個方法的代碼如下,

public Resource[] getResources(String locationPattern) throws IOException { Assert.notNull(locationPattern, "Location pattern must not be null"); // 在ResourcePatternResolver接口中聲明:String CLASSPATH_ALL_URL_PREFIX = "classpath*:"; if (locationPattern.startsWith(CLASSPATH_ALL_URL_PREFIX)) { // 處理classpath*:前綴的location配置 // 這里默認的模式匹配器是AntPathMatcher,即處理ant風格的匹配 if (getPathMatcher().isPattern(locationPattern.substring(CLASSPATH_ALL_URL_PREFIX.length()))) { // 查找與匹配模式匹配的資源,詳見2.2.3 return findPathMatchingResources(locationPattern); } else { // 沒有使用通配符,返回classes路徑下和所有jar包中的所有相匹配的資源 return findAllClassPathResources(locationPattern.substring(CLASSPATH_ALL_URL_PREFIX.length())); } } else { // Note:這里只會查找第一個根目錄下面的所有相匹配的資源 // 檢查模式是否被匹配器匹配 int prefixEnd = locationPattern.indexOf(":") + 1; if (getPathMatcher().isPattern(locationPattern.substring(prefixEnd))) { // 查找與匹配模式匹配的資源 return findPathMatchingResources(locationPattern); } else { // locationPattern沒有使用通配符 // 只加載第一個找到的資源,默認使用DefaultResourceLoader的getResource方法 // 詳見1部分 return new Resource[] {getResourceLoader().getResource(locationPattern)}; } } }

這段代碼主要是對locationPattern參數做分類,然后根據不同的分類調用相應的處理方法,它把locationPattern分成以下四種情況:

第一種是前綴為classpath*:且含有通配符,這種情況將查找與匹配模式匹配的所有資源;

第二種是前綴為classpath*:但不含通配符,這種情況返回classes路徑和jar包中匹配的所有資源;

第三種是前綴不為classpath*:為前綴且含有通配符,這種情況與第一種情況有點類似,同樣是查找與匹配器相匹配的資源,但只返回找到的第一個根目錄下的所有與匹配模式匹配的資源;

第四種是前綴不為classpath*:為前綴且不含通配符,這種情況只返回查找到的第一個資源,詳見第1節——根據具體的路徑加載資源。

上面代碼spring的開發者寫的有點繞,仔細分析這段代碼,對于第一種情況和第三種情況,判斷邏輯其實都是一樣的,開發者完全可以把這段代碼合成一段。下面是我通過繼承PathMatchingResourcePatternResolver重寫了getResources接口,代碼如下。點此下載

public class MyPathMatchingResourcePatternResolver extends PathMatchingResourcePatternResolver{ public MyPathMatchingResourcePatternResolver(ClassLoader classLoader) { super(classLoader); } @Override public Resource[] getResources(String locationPattern) throws IOException { int prefixEnd = locationPattern.indexOf(":") + 1; if (getPathMatcher().isPattern(locationPattern.substring(prefixEnd))) { // 查找與匹配模式匹配的資源 return findPathMatchingResources(locationPattern); } // 不使用通配符 if (locationPattern.startsWith(CLASSPATH_ALL_URL_PREFIX)) { // 返回classes路徑下和所有jar包中的所有相匹配的資源 return findAllClassPathResources(locationPattern.substring(CLASSPATH_ALL_URL_PREFIX.length())); } // 只加載一個資源 return new Resource[] {getResourceLoader().getResource(locationPattern)}; }}

這段代碼我只把locationPattern分成三種情況:第一種是含有通配符的,第二種是以classpath*:為前綴但沒有使用通配符的,第三種是沒有以classpath*:為前綴也沒有使用通配符的。

對于只加載一個資源的情況已經在第1節中探討了。下面先來看看spring如何處理以classpath*:為前綴但沒使用通配符情況,再回過頭來看spring如何處理使用通配符的情況。

2.1 加載與以classpath*:為前綴但沒有使用通配符的location相匹配的資源。 在PathMatchingResourcePatternResolver的getResources(String locationPattern)方法中對于以classpath*:為前綴但沒有使用通配符的location參數是通過調用它的findAllClassPathResources(String location)方法來創建相應的Resource對象的,代碼如下。

protected Resource[] findAllClassPathResources(String location) throws IOException { String path = location; if (path.startsWith("/")) { path = path.substring(1); } Set<Resource> result = doFindAllClassPathResources(path); if (logger.isDebugEnabled()) { logger.debug("Resolved classpath location [" + location + "] to resources " + result); } return result.toArray(new Resource[result.size()]); } protected Set<Resource> doFindAllClassPathResources(String path) throws IOException { Set<Resource> result = new LinkedHashSet<Resource>(16); ClassLoader cl = getClassLoader(); // 獲取class路徑和jar包下相匹配的文件url Enumeration<URL> resourceUrls = (cl != null ? cl.getResources(path) : ClassLoader.getSystemResources(path)); while (resourceUrls.hasMoreElements()) { URL url = resourceUrls.nextElement(); result.add(convertClassLoaderURL(url)); } if ("".equals(path)) { // 獲取所有的jar包 addAllClassLoaderJarRoots(cl, result); } return result; } /** * 返回一個UrlResource對象 */ protected Resource convertClassLoaderURL(URL url) { return new UrlResource(url); }

findAllClassPathResources方法通過ClassLoader對象來加載指定名稱的資源,不管它在classes路徑下還是任何jar包中。如果path參數為空字符串,那么將調用addAllClassLoaderJarRoots方法獲取所有jar包。

2.2 加載與含有通配符的location參數相匹配的資源。 如果location參數中使用了通配符,那么PathMatchingResourcePatternResolver將調用它的findPathMatchingResources(String locationPattern)方法,代碼如下。

protected Resource[] findPathMatchingResources(String locationPattern) throws IOException { // 獲取文件所在的根目錄,不含通配符 String rootDirPath = determineRootDir(locationPattern); // 獲取含有通配符部分的字符串 String subPattern = locationPattern.substring(rootDirPath.length()); / 把根目錄封裝成Resource對象 Resource[] rootDirResources = getResources(rootDirPath); // 遍歷查找到的根目錄資源,這些根目錄可能是來自class路徑、jar包、zip等其他壓縮包等 Set<Resource> result = new LinkedHashSet<Resource>(16); for (Resource rootDirResource : rootDirResources) { rootDirResource = resolveRootDirResource(rootDirResource); URL rootDirURL = rootDirResource.getURL(); if (equinoxResolveMethod != null) { if (rootDirURL.getProtocol().startsWith("bundle")) { // 執行resolver方法進行協議轉換 rootDirURL = (URL) ReflectionUtils.invokeMethod(equinoxResolveMethod, null, rootDirURL); rootDirResource = new UrlResource(rootDirURL); } } if (rootDirURL.getProtocol().startsWith(ResourceUtils.URL_PROTOCOL_VFS)) { // 從vfs中加載匹配的資源 result.addAll(VfsResourceMatchingDelegate.findMatchingResources(rootDirURL, subPattern, getPathMatcher())); } else if (ResourceUtils.isJarURL(rootDirURL) || isJarResource(rootDirResource)) { // 從jar包中加載匹配的資源 result.addAll(doFindPathMatchingJarResources(rootDirResource, rootDirURL, subPattern)); } else { // 從文件系統中加載匹配的資源 result.addAll(doFindPathMatchingFileResources(rootDirResource, subPattern)); } } if (logger.isDebugEnabled()) { logger.debug("Resolved location pattern [" + locationPattern + "] to resources " + result); } return result.toArray(new Resource[result.size()]); } /** * 根據指定location查找根目錄。比如location為“/WEB-INF/config/*.xml”,根目錄為“/WEB-INF/config/” */ protected String determineRootDir(String location) { int prefixEnd = location.indexOf(":") + 1; int rootDirEnd = location.length(); while (rootDirEnd > prefixEnd && getPathMatcher().isPattern(location.substring(prefixEnd, rootDirEnd))) { rootDirEnd = location.lastIndexOf('/', rootDirEnd - 2) + 1; } if (rootDirEnd == 0) { rootDirEnd = prefixEnd; } return location.substring(0, rootDirEnd); }

findPathMatchingResources方法主要是獲取根目錄資源,然后根據根目錄的類型調用相應的方法來獲取根目錄下的資源。它把根目錄分為三類,其一vfs中的目錄,其二是jar包中的目錄,其三是文件系統中的目錄。

(1)加載vfs下的資源 如果目錄在vfs中,PathMatchingResourcePatternResolver會調用它的私有靜態內部類VfsResourceMatchingDelegate 的靜態方法findMatchingResources來加載vfs中的資源,代碼如下。

private static class VfsResourceMatchingDelegate { public static Set<Resource> findMatchingResources( URL rootDirURL, String locationPattern, PathMatcher pathMatcher) throws IOException { Object root = VfsPatternUtils.findRoot(rootDirURL); PatternVirtualFileVisitor visitor = new PatternVirtualFileVisitor(VfsPatternUtils.getPath(root), locationPattern, pathMatcher); VfsPatternUtils.visit(root, visitor); return visitor.getResources(); } }

(2)加載jar包目錄下的資源 如果目錄在jar包中,PathMatchingResourcePatternResolver執行 doFindPathMatchingJarResources(Resource rootDirResource, URL rootDirURL, String subPattern)方法,代碼如下。

protected Set<Resource> doFindPathMatchingJarResources(Resource rootDirResource, URL rootDirURL, String subPattern) throws IOException { Set<Resource> result = doFindPathMatchingJarResources(rootDirResource, subPattern); if (result != null) { return result; } URLConnection con = rootDirURL.openConnection(); JarFile jarFile; String jarFileUrl; String rootEntryPath; boolean closeJarFile; if (con instanceof JarURLConnection) { // Should usually be the case for traditional JAR files. JarURLConnection jarCon = (JarURLConnection) con; ResourceUtils.useCachesIfNecessary(jarCon); jarFile = jarCon.getJarFile(); jarFileUrl = jarCon.getJarFileURL().toExternalForm(); JarEntry jarEntry = jarCon.getJarEntry(); rootEntryPath = (jarEntry != null ? jarEntry.getName() : ""); closeJarFile = !jarCon.getUseCaches(); } else { String urlFile = rootDirURL.getFile(); try { // 聲明:public static final String JAR_URL_SEPARATOR = "!/"; int separatorIndex = urlFile.indexOf(ResourceUtils.JAR_URL_SEPARATOR); if (separatorIndex != -1) { jarFileUrl = urlFile.substring(0, separatorIndex); rootEntryPath = urlFile.substring(separatorIndex + ResourceUtils.JAR_URL_SEPARATOR.length()); jarFile = getJarFile(jarFileUrl); } else { jarFile = new JarFile(urlFile); jarFileUrl = urlFile; rootEntryPath = ""; } closeJarFile = true; } catch (ZipException ex) { if (logger.isDebugEnabled()) { logger.debug("Skipping invalid jar classpath entry [" + urlFile + "]"); } return Collections.emptySet(); } } try { if (logger.isDebugEnabled()) { logger.debug("Looking for matching resources in jar file [" + jarFileUrl + "]"); } if (!"".equals(rootEntryPath) && !rootEntryPath.endsWith("/")) { // 確保rootEntryPath以'/'結尾 rootEntryPath = rootEntryPath + "/"; } result = new LinkedHashSet<Resource>(8); // 遍歷目錄下的文件 for (Enumeration<JarEntry> entries = jarFile.entries(); entries.hasMoreElements();) { JarEntry entry = entries.nextElement(); String entryPath = entry.getName(); if (entryPath.startsWith(rootEntryPath)) { String relativePath = entryPath.substring(rootEntryPath.length()); // 判斷當前資源路徑是否與指定模式匹配 if (getPathMatcher().match(subPattern, relativePath)) { result.add(rootDirResource.createRelative(relativePath)); } } } return result; } finally { if (closeJarFile) { jarFile.close(); } } } protected JarFile getJarFile(String jarFileUrl) throws IOException { // 聲明:public static final String FILE_URL_PREFIX = "file:"; if (jarFileUrl.startsWith(ResourceUtils.FILE_URL_PREFIX)) { try { return new JarFile(ResourceUtils.toURI(jarFileUrl).getSchemeSpecificPart()); } catch (URISyntaxException ex) { return new JarFile(jarFileUrl.substring(ResourceUtils.FILE_URL_PREFIX.length())); } } else { return new JarFile(jarFileUrl); } }

(3)從文件系統中加載資源 如果根目錄不在jar包或者vfs中,PathMatchingResourcePatternResolver會把根目錄當成本地文件系統中的目錄,調用它的 doFindPathMatchingFileResources(Resource rootDirResource, String subPattern)方法來實現,這個方法的代碼如下。

protected Set<Resource> doFindPathMatchingFileResources(Resource rootDirResource, String subPattern) throws IOException { File rootDir; try { // 獲取根目錄File對象 rootDir = rootDirResource.getFile().getAbsoluteFile(); } catch (IOException ex) { if (logger.isWarnEnabled()) { logger.warn("Cannot search for matching files underneath " + rootDirResource + " because it does not correspond to a directory in the file system", ex); } return Collections.emptySet(); } // 從文件系統中查找匹配的資源 return doFindMatchingFileSystemResources(rootDir, subPattern); }

上面代碼主要是獲取根目錄文件,同時也檢查根目錄是否存在,然后調用PathMatchingResourcePatternResolver對象的doFindMatchingFileSystemResources方法,代碼如下。

/** * 從文件系統中查找匹配的資源 */ protected Set<Resource> doFindMatchingFileSystemResources(File rootDir, String subPattern) throws IOException { if (logger.isDebugEnabled()) { logger.debug("Looking for matching resources in directory tree [" + rootDir.getPath() + "]"); } // 獲取匹配的文件 Set<File> matchingFiles = retrieveMatchingFiles(rootDir, subPattern); Set<Resource> result = new LinkedHashSet<Resource>(matchingFiles.size()); for (File file : matchingFiles) { // 使用FileSystemResource對象封裝匹配的文件對象 result.add(new FileSystemResource(file)); } return result; }

doFindMatchingFileSystemResources方法主要做的事情是調用PathMatchingResourcePatternResolver對象的retrieveMatchingFiles方法來獲取根目錄下與指定模式匹配的文件(見下面代碼)。然后把匹配的文件封裝到FileSystemResource對象中。

/** * 獲取匹配的文件 */ protected Set<File> retrieveMatchingFiles(File rootDir, String pattern) throws IOException { // 判斷根文件是否存在 if (!rootDir.exists()) { if (logger.isDebugEnabled()) { logger.debug("Skipping [" + rootDir.getAbsolutePath() + "] because it does not exist"); } return Collections.emptySet(); } // 判斷根文件是否是目錄文件 if (!rootDir.isDirectory()) { // Complain louder if it exists but is no directory. if (logger.isWarnEnabled()) { logger.warn("Skipping [" + rootDir.getAbsolutePath() + "] because it does not denote a directory"); } return Collections.emptySet(); } // 判斷根目錄是否可讀 if (!rootDir.canRead()) { if (logger.isWarnEnabled()) { logger.warn("Cannot search for matching files underneath directory [" + rootDir.getAbsolutePath() + "] because the application is not allowed to read the directory"); } return Collections.emptySet(); } // 獲取完整的模式路徑 String fullPattern = StringUtils.replace(rootDir.getAbsolutePath(), File.separator, "/"); if (!pattern.startsWith("/")) { fullPattern += "/"; } fullPattern = fullPattern + StringUtils.replace(pattern, File.separator, "/"); Set<File> result = new LinkedHashSet<File>(8); // 把匹配的文件放到result對象中 doRetrieveMatchingFiles(fullPattern, rootDir, result); return result; }

retrieveMatchingFiles方法主要做的事情是保證傳入的根文件必須存在、必須目錄和必須可讀,以及調用doRetrieveMatchingFiles方法來獲取匹配的文件。

protected void doRetrieveMatchingFiles(String fullPattern, File dir, Set<File> result) throws IOException { if (logger.isDebugEnabled()) { logger.debug("Searching directory [" + dir.getAbsolutePath() + "] for files matching pattern [" + fullPattern + "]"); } // 獲取目錄中所有的文件 File[] dirContents = dir.listFiles(); if (dirContents == null) { if (logger.isWarnEnabled()) { logger.warn("Could not retrieve contents of directory [" + dir.getAbsolutePath() + "]"); } return; } Arrays.sort(dirContents); // 遍歷目錄中的文件 for (File content : dirContents) { String currPath = StringUtils.replace(content.getAbsolutePath(), File.separator, "/"); // 檢查子文件是否為目錄,且是否與指定的模式開頭部分匹配 if (content.isDirectory() && getPathMatcher().matchStart(fullPattern, currPath + "/")) { if (!content.canRead()) { if (logger.isDebugEnabled()) { logger.debug("Skipping subdirectory [" + dir.getAbsolutePath() + "] because the application is not allowed to read the directory"); } } else { // 遞歸掃描子目錄 doRetrieveMatchingFiles(fullPattern, content, result); } } // 檢查子文件路徑是否與指定的模全匹配 if (getPathMatcher().match(fullPattern, currPath)) { result.add(content); } } }

doRetrieveMatchingFiles方法是獲取匹配文件的終極方法,這個方法遍歷指定的根目錄下的所有文件,并把匹配的文件放到指定的Set對象中。

總結


spring支持的location前綴有多種,可以為任何網絡協議為,比如http:、ftp:、file:等。也可以為classpath:、classpath*:,此時加載的為classes路徑下和jar包中的文件。也可以沒有前綴,此時加載的是相對于當前資源所在路徑下的文件。

關于classpath:和classpath*:的區別。classpath:掃描的范圍更小,它只加載第一個匹配的根目錄下所匹配的資源;classpath*:掃描的范圍更廣,它查找所有匹配的根目錄下所匹配的資源。

spring支持ant風格的location。但是要加載的資源為其他服務器上的資源,不能使用ant風格,必須為一個明確的地址,比如http://special.csdncms.csdn.net/programmer-covers。


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
日韩欧美亚洲国产| 亚洲 国产 欧美 日韩| 香蕉人人精品| 最近中文字幕在线中文高清版| 久久精品电影| 欧美激情一区二区三区在线| 精品播放一区二区| 亚洲高清视频在线| 一区二区中文字幕在线| 99精品在线播放| 亚洲免费观看在线观看| 在线国产91| 亚洲午夜久久| 欧美日韩国产不卡| 国产一卡2卡3卡4卡网站免费| 亚洲va中文字幕| 欧美国产一级片| 一区二区在线观| 麻豆一区二区99久久久久| av不卡免费看| 一本久久a久久精品亚洲| 国产无套粉嫩白浆在线2022年| 国产乱码在线观看| av首页在线| 国产亚洲福利| www 日韩| 亚洲天堂国产视频| 欧美日韩国产在线看| 中文字幕日韩欧美在线| 一区二区三区在线免费| 国产无遮挡在线视频免费观看| 精品调教chinesegay| 欧美日韩色综合| 国产嫩草影院久久久久| 欧美日韩精品是欧美日韩精品| 国产视频二区| 日韩在线视频一区二区三区| 亚洲经典中文字幕| 国产在成人精品线拍偷自揄拍| 国产高清视频一区二区| 色www精品视频在线观看| 亚洲日本精品视频| 国内国产区免费视频| 一级日韩一级欧美| 亚洲欧洲综合另类| 日韩欧美国产视频| 欧美日韩中文国产| 欧美日韩在线不卡一区| 亚洲一区在线观看免费| 亚洲国产无线乱码在线观看| 国产福利精品导航| 久久久99精品久久| 国产网站欧美日韩免费精品在线观看| 国产羞羞视频在线播放| 日韩欧美在线网站| 国产日产一区二区| 国产一级一片免费播放| 高清1区2区| 亚洲乱码视频| 午夜一区二区三区| 欧美国产小视频| 麻豆一区二区99久久久久| 午夜视频在线观看一区| 国内国产区免费视频| 久久久99久久精品欧美| 中文字幕在线高清| 91久久精品国产91性色69| 日韩专区中文字幕| 欧美日韩三级在线| 日韩亚洲国产欧美| 成人禁用看黄a在线| 一区二区91| 三级网站免费观看| 国产三级视频在线| 亚洲国产无线乱码在线观看| 中文字幕在线精品| 黄色国产在线| 精品国产网站在线观看| 欧美国产小视频| 久久精品国产91精品亚洲| 不卡一二三区| 激情五月综合| 精品在线观看一区| 国产一级一片免费播放| 91蜜桃在线视频| 亚洲精品欧美二区三区中文字幕| 一本一道久久a久久精品综合蜜臀| www日韩在线观看| 日韩中文字幕在线观看视频| 精品999在线| 欧美日韩国产高清| 国产在线视频不卡| 欧美不卡一二三| 91精品久久久久久久久| 午夜国产视频 | 日韩欧美一级在线| 中文字幕第一页在线播放| 亚洲黄页一区| 国产视频2区| 久久99蜜桃精品| 中文字幕在线官网| 国产一卡2卡3卡4卡网站免费| 国产天堂素人系列在线视频| 日韩精品在线看| 中文字幕 亚洲一区| 国产手机精品视频| 先锋男人资源站| 精品国产1区2区3区| 欧美日韩国产综合视频在线观看| 天天综合天天| 欧美在线视频一区二区| 99pao成人国产永久免费视频| 色猫猫国产区一区二在线视频 | 精品在线一区二区| 91精品国产网站| 欧美熟妇乱码在线一区| 91精品国产网站| 中文字幕欧美人妻精品一区蜜臀| 日韩精品乱码av一区二区| 日韩欧美亚洲国产一区| 日韩在线视频一区| 91精品久久久久久蜜臀| 日本国产在线视频| 亚洲成人7777| 国产一二三精品| 欧美 日韩 国产 高清| 国产亚洲一区字幕| 欧美日韩精品在线视频| 国产小视频免费在线网址| 久久精品国产视频| 中文字幕人成乱码在线观看| 日韩中文在线视频| 欧美日韩在线国产| 影音先锋一区二区资源站| 精品福利一区二区三区| 日韩中文字幕在线播放| 中文字幕日韩高清| 亚洲欧美日本国产专区一区| 中文字幕 欧美日韩| 日韩精品a在线观看91| 99pao成人国产永久免费视频| 精品三级久久| 国产99亚洲| 精品一二三四| aaa免费看大片| 国产在线www| 欧美日韩中文字幕在线观看| 国产一区在线不卡| 免费日韩精品中文字幕视频在线| 亚洲三级国产| 欧美亚洲另类制服自拍| 国产对白在线| 国产区在线看| 欧美日韩在线视频免费观看| 精品国产99| 91精品国产免费久久综合| 久久综合九色欧美综合狠狠| 77777_亚洲午夜久久多人 | 精品久久九九| 精品日韩视频| 在线观看av的网站| 国产一区不卡精品| 日韩欧美国产成人一区二区| 欧美日韩国产91| 日韩中文字幕二区| 热久久精品国产| 欧美日韩尤物久久| 欧美日韩高清一区二区| 日韩久久精品视频| 国产一卡2卡3卡免费网站| 日韩你懂的电影在线观看| 国产乱码在线观看| 日韩视频中文字幕| 亚洲福利在线看| 51精品免费网站| 精品999视频| 日韩美女视频一区二区在线观看| 国产h片在线观看| 国产久卡久卡久卡久卡视频精品| 国产在线导航| 日韩一级免费在线观看| 日韩国产欧美在线视频| 午夜一区二区三区免费| 国产极品嫩模在线视频一区 | 国产欧美日韩精品高清二区综合区 | 国产高清在线视频| 国产手机视频一区二区| 91精品国产调教在线观看| 欧美不卡123| 欧美日韩国产123区| 国产欧美综合在线观看第十页| 欧美日韩精品久久久| 欧美日韩国产在线| 中文字幕亚洲二区| 日韩精品视频在线观看视频| 中文字幕欧美人妻精品一区蜜臀 | 久久精品最新免费国产成人| 精品三区视频| 免费视频一区三区| 激情五月综合| 精品三级av| 国产伦精品免费视频| 深夜福利一区二区| 欧美不卡一区二区| 中文字幕 欧美日韩| 日韩在线高清| 国产欧美日韩第一页| 亚洲影视资源网| 亚州黄色一级| 韩日中文字幕第一页| 亚洲欧美中文字幕| 精品久久91| 国产一区二中文字幕在线看| 日韩欧美一二三| 中文字幕在线看视频国产欧美| 一区二区不卡视频| 精品调教chinesegay| 国产福利在线看| 欧美三级在线看| 国产不卡的av| av午夜在线| 九七久久人人| 日韩在线观看一区| 在线不卡一区二区| 国产日韩三级| 91精品国产91久久久久久久久| 成人一区二区不卡免费| 日韩免费不卡avV| 日韩在线小视频| 欧美日韩中文字幕视频| 一区二区三区鲁丝不卡| 欧美日韩视频免费| 天天摸日日摸狠狠添| 精品日韩av| 午夜影院在线观看欧美| 91精品在线视频观看| 国产三级精品网站| 久久韩国免费视频| 一区二区高清视频| 在线日韩中文字幕| 日韩中文在线中文网三级| 亚洲福利精品视频| 中文字幕中文字幕精品| 久99久视频| 国产亚洲一级| 91精品久久久久| 亚洲免费中文字幕| 国产91大片| 日韩欧美中文在线| 久久综合九色欧美综合狠狠| 亚洲综合在线小说| 国产欧美日韩在线视频| 粉嫩喷白浆久久| 亚洲视频在线观看日本a| 欧美日韩成人综合| 日韩精品丝袜在线| 久久久久久欧美| 午夜国产在线视频| 午夜国产福利一区二区| 亚洲专区一区| av免费观看国产| 日韩国产91| 精品日韩99亚洲| 国产免费久久| 91精品国产综合久久久久久漫画| 日韩欧美一卡二卡| 一级一片免费视频| 欧美天堂一区二区| 欧美日韩国产一区在线| 日韩欧美中文字幕一区| 欧美中日韩在线| 亚洲一区在线观看网站| 内射国产内射夫妻免费频道| 国产日韩精品久久久| 欧美日韩在线精品成人综合网| 欧美性极品xxxx做受| 91精品国产综合久久久久久 | 婷婷中文字幕综合| 国产欧美在线观看| 日韩在线中文| 国产视频二区| 亚洲娇小xxxx欧美娇小| 一区二区精品| 欧美日韩一二三| 中文字幕在线欧美| 日韩在线视频免费观看高清中文| 日本精品在线播放| 丰满少妇一区| 日韩视频在线一区二区| 中文字幕第一页在线播放| 国产欧美日韩中文字幕| 免费精品国产自产拍观看| 国产婷婷一区二区| 日本精品免费观看高清观看| 在线视频第一页| 日韩在线观看视频一区| 91精品久久久久久蜜臀| 欧美日韩国产综合久久| 99在线精品视频免费观看20| 亚洲一二三不卡| 日韩三区免费| 欧美日韩国产免费观看视频| 精品全国在线一区二区| 欧洲精品久久久| 日韩欧美中文字幕视频| 国产欧美综合在线观看第十页| 最近高清中文在线字幕在线观看1| 日韩在线高清| 精品一区二区在线观看视频| 国产久卡久卡久卡久卡视频精品| 国产一区久久| 99久热re在线精彩视频| 婷婷中文字幕一区三区| 日韩三级视频在线| 欧美三级日本三级少妇99| 日韩欧美在线中字| 91xxx在线观看| 搞黄在线观看| 久久精品人妻一区二区三区| 日韩a一区二区| 日韩国产专区| 亚洲国产无线乱码在线观看| 精品久久久久久综合日本欧美| 日本啊v在线| 中文字幕精品国产| 中文字幕亚洲国产| 国产不卡在线| 中文字幕日韩欧美| 欧美日韩高清一区二区| 日韩wumaV| 亚洲女人天堂a在线播放| 欧美大片在线观看一区| 亚洲第一视频网站| 99在线国产| 国产黄色在线播放| 一区二区三区精品久久久| 精品中文字幕视频| 欧美三级中文字幕| 精品成人久久av| 亚洲欧美视频一区二区三区| 日韩精品手机在线观看| 日韩精品在线看| 欧美中文字幕视频| 国产欧美日韩中文久久| 亚洲视频 中文字幕| 日韩国产一区| www.eeuss影院| 欧美日韩国产一二三| 99久久婷婷| 中文字幕 日韩 欧美| 欧美日韩国产三级| 日韩精品在线免费播放| 不卡一二三区| 久久99精品久久久| 国产日韩av一区| 日韩国产欧美在线视频| 中文字幕精品视频| 黄色国产网站在线观看| 国产福利久久久| 精品国产欧美日韩不卡在线观看| 国内精品露脸在线视频播放| 欧美日韩国产专区| 国产高清精品在线观看| 日韩欧美国产免费播放| 日韩欧美中文字幕视频| 日本精品在线| 一级国产黄色片| 91亚洲国产| 国产婷婷一区二区| 日韩一级视频在线观看| 亚洲一区资源| 欧美日韩在线视频免费观看| 国产欧美日韩精品在线| 日韩欧美综合在线| 亚洲一区中文在线| 一区二区三区在线播放欧美| 粉嫩粉嫩芽的虎白女18在线视频| 欧美日韩91| 欧美一级手机免费观看片| 亚洲视频一二三四| 影音先锋一区二区资源站| 日本一欧美一欧美一亚洲视频| 黄色一区二区视频| 欧美日韩国产中文精品字幕自在自线 | 不卡视频一区二区| 一区二区在线视频播放| 男人的天堂网av| 亚洲一区在线观看视频| 人成免费在线视频| 在线精品视频免费播放| 日韩欧美三级| 在线看的av| 国产一区在线不卡| 日韩不卡中文字幕| 国产欧美日韩不卡| 久久91精品国产91久久小草| 欧美不卡视频一区| 精品久久蜜桃| 亚洲一区在线观看免费| 欧美 日韩 国产 高清|