亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb

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

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。


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb
亚洲片在线资源| 欧美黄色片免费观看| 亚洲色图15p| 欧美日韩亚洲激情| 91中文字幕一区| 久99久在线视频| 久青草国产97香蕉在线视频| 欧美大成色www永久网站婷| 国产精品白嫩美女在线观看| 久99九色视频在线观看| 日韩三级成人av网| 国产99久久精品一区二区永久免费| 久久久日本电影| 精品久久久久久| 91丨九色丨国产在线| 亚洲男人天堂手机在线| 色噜噜狠狠狠综合曰曰曰88av| 国产精品一区二区性色av| 国产91亚洲精品| 欧美成aaa人片在线观看蜜臀| 欧美日韩成人网| 日韩一区二区av| 欧美激情视频在线观看| 成人精品一区二区三区| 奇米四色中文综合久久| 亚洲美女性生活视频| 欧美孕妇性xx| zzjj国产精品一区二区| 91亚洲精华国产精华| 热re91久久精品国99热蜜臀| 日韩电影中文字幕在线观看| 欧美丝袜一区二区三区| 国产日韩在线精品av| 精品久久久av| 国产剧情日韩欧美| 91久久精品国产91性色| 亚洲欧美另类人妖| 亚洲国产精品一区二区久| 久久亚洲精品小早川怜子66| 精品福利视频导航| 中日韩美女免费视频网站在线观看| 日韩中文字幕国产| 欧美精品第一页在线播放| 日韩中文字幕在线视频| 欧美黑人一级爽快片淫片高清| 97超级碰在线看视频免费在线看| 精品中文字幕在线观看| 91经典在线视频| 色妞在线综合亚洲欧美| 成人写真福利网| 久久久久久久亚洲精品| 国产精品大陆在线观看| 51视频国产精品一区二区| 久久久精品免费| 欧美电影免费观看高清| 97超级碰碰人国产在线观看| 人人爽久久涩噜噜噜网站| 亚洲欧美在线免费观看| 在线观看视频99| 色婷婷久久一区二区| 国产精品高潮呻吟久久av野狼| 青青久久av北条麻妃海外网| 视频在线一区二区| 精品久久久久久亚洲国产300| 亚洲高清在线观看| 欧美一级淫片播放口| 国产精品人成电影| 日韩久久精品电影| 日韩av影院在线观看| 6080yy精品一区二区三区| 亚洲午夜女主播在线直播| 久久综合网hezyo| 欧美日韩高清区| 欧美激情久久久久| 欧美激情乱人伦| 久久久精品久久久| 久久精品成人欧美大片古装| 久久91精品国产91久久跳| 欧美日韩国产成人在线| 国产成人精品电影久久久| 欧美黑人国产人伦爽爽爽| 91免费福利视频| 97成人精品区在线播放| 欧美二区乱c黑人| 中文字幕av一区二区| 欧美日韩免费一区| 色综合视频一区中文字幕| 2021国产精品视频| 97在线免费观看视频| 91九色蝌蚪国产| 日韩欧美在线一区| 51精品国产黑色丝袜高跟鞋| 欧美午夜视频在线观看| www.亚洲人.com| 日本欧美爱爱爱| 亚洲激情视频网| 中文字幕成人在线| 国产精品福利无圣光在线一区| 欧美在线观看视频| 精品夜色国产国偷在线| 中文字幕av一区二区三区谷原希美| 91九色在线视频| 青青草精品毛片| 欧美精品video| 亚洲人成亚洲人成在线观看| 91系列在线播放| 亚洲视频在线免费观看| 69av视频在线播放| 欧美激情免费观看| 午夜精品一区二区三区av| 91免费人成网站在线观看18| 国产日韩欧美在线| 精品国偷自产在线视频| 欧美国产日本高清在线| 亚洲精品av在线| 日韩av在线网| 亚洲精美色品网站| 国产日本欧美一区二区三区在线| 国产精品99久久久久久白浆小说| 免费av在线一区| 欧美日韩一二三四五区| 91极品视频在线| 国产91精品久久久久| 欧美另类极品videosbestfree| 久久伊人精品视频| 深夜成人在线观看| 国产美女扒开尿口久久久| 精品视频在线观看日韩| www.亚洲免费视频| 欧美xxxx做受欧美.88| 国产精品偷伦免费视频观看的| 日韩av最新在线| 日韩av电影在线播放| 亚洲激情成人网| 久久夜色精品亚洲噜噜国产mv| 国产欧美日韩中文字幕| 日本亚洲欧洲色α| 色多多国产成人永久免费网站| 久久av.com| 一区二区国产精品视频| 亚洲成人久久久| 91精品视频免费| 欧美成人剧情片在线观看| 久久精品国产清自在天天线| 亚洲一区二区福利| 日韩美女福利视频| 色综合视频网站| 欧美国产视频一区二区| 久久中文精品视频| 亚洲国产精品va在线看黑人| 中文字幕亚洲一区二区三区| 国产综合视频在线观看| 亚洲自拍av在线| 国产精品视频白浆免费视频| 91av网站在线播放| 中文字幕久热精品视频在线| 中文字幕亚洲一区二区三区五十路| 91精品综合久久久久久五月天| 91精品中文在线| 国产精品视频免费在线观看| 久久久中精品2020中文| 欧美另类老女人| 欧美激情二区三区| 欧美激情亚洲国产|