本文共 1639 字,大约阅读时间需要 5 分钟。
PathMatchingResourcePatternResolver
根据包路径得到所有匹配的类路径
protected SetdoFindAllClassPathResources(String path) throws IOException { Set result = new LinkedHashSet<>(16); ClassLoader cl = getClassLoader(); Enumeration resourceUrls = (cl != null ? cl.getResources(path) : ClassLoader.getSystemResources(path)); while (resourceUrls.hasMoreElements()) { URL url = resourceUrls.nextElement(); result.add(convertClassLoaderURL(url)); } if ("".equals(path)) { // The above result is likely to be incomplete, i.e. only containing file system references. // We need to have pointers to each of the jar files on the classpath as well... addAllClassLoaderJarRoots(cl, result); } return result; }
根据类路径,得到匹配的所有的class文件
protected void doRetrieveMatchingFiles(String fullPattern, File dir, Setresult) throws IOException { if (logger.isTraceEnabled()) { logger.trace("Searching directory [" + dir.getAbsolutePath() + "] for files matching pattern [" + fullPattern + "]"); } for (File content : listDirectory(dir)) { 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); } } }
转载地址:http://ovxwb.baihongyu.com/