當前位置: 首頁>>代碼示例>>Java>>正文


Java ResourcePatternResolver.getResources方法代碼示例

本文整理匯總了Java中org.springframework.core.io.support.ResourcePatternResolver.getResources方法的典型用法代碼示例。如果您正苦於以下問題:Java ResourcePatternResolver.getResources方法的具體用法?Java ResourcePatternResolver.getResources怎麽用?Java ResourcePatternResolver.getResources使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.springframework.core.io.support.ResourcePatternResolver的用法示例。


在下文中一共展示了ResourcePatternResolver.getResources方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: validateResource

import org.springframework.core.io.support.ResourcePatternResolver; //導入方法依賴的package包/類
public static void validateResource(String resourcePath,Logger log) 
{ 

	ResourcePatternResolver resourceResolver = new PathMatchingResourcePatternResolver();
	try {
		if (resourceResolver.getResources("classpath*:/GameData" +resourcePath+"*").length==0)
			log.error("INEXISTENT RESOURCE "+"/GameData" +resourcePath+"*");
	} catch (IOException e) {
		// TODO Auto-generated catch block 
		e.printStackTrace();
	}
}
 
開發者ID:GastonMauroDiaz,項目名稱:buenojo,代碼行數:13,代碼來源:ResourceHelper.java

示例2: scanPackages

import org.springframework.core.io.support.ResourcePatternResolver; //導入方法依賴的package包/類
/**
 * <p>根據多個包名搜索class
 * 例如: ScanClassUtils.scanPakcages("javacommon.**.*");</p>
 * 
 * @param basePackages 各個包名使用逗號分隔,各個包名可以有通配符
 * @return 類名的集合
 */
@SuppressWarnings("all")
public static List<String> scanPackages(String basePackages) {
	Assert.notNull(basePackages,"'basePakcages' must be not null");
	ResourcePatternResolver rl = new PathMatchingResourcePatternResolver();
	MetadataReaderFactory metadataReaderFactory = new CachingMetadataReaderFactory(rl); 
	List<String> result = new ArrayList<String>();
	String[] arrayPackages = basePackages.split(",");
	try {
		for(int j = 0; j < arrayPackages.length; j++) {
			String packageToScan = arrayPackages[j];
			String packagePart = packageToScan.replace('.', '/');
			String classPattern = "classpath*:/" + packagePart + "/**/*.class";
			Resource[] resources = rl.getResources(classPattern);
			for (int i = 0; i < resources.length; i++) {
				Resource resource = resources[i];
				MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(resource);   
				String className = metadataReader.getClassMetadata().getClassName();
				result.add(className);
			}
		}
	} catch(Exception e) {
		throw new RuntimeException(String.format("Scanning package[%s] class occurred an error!", basePackages), e);
	}
	return result;
}
 
開發者ID:penggle,項目名稱:xproject,代碼行數:33,代碼來源:ClassScanningUtils.java

示例3: findMyTypes

import org.springframework.core.io.support.ResourcePatternResolver; //導入方法依賴的package包/類
protected List<Class<?>> findMyTypes(String basePackage) throws IOException, ClassNotFoundException {
	ResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver();
	MetadataReaderFactory metadataReaderFactory = new CachingMetadataReaderFactory(resourcePatternResolver);

	List<Class<?>> candidates = new ArrayList<>();
	String packageSearchPath = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + resolveBasePackage(basePackage)
	                           + "/" + "**/*.class";
	Resource[] resources = resourcePatternResolver.getResources(packageSearchPath);
	for (Resource resource : resources) {
		if (resource.isReadable()) {
			MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(resource);
			if (isCandidate(metadataReader)) {
				candidates.add(forName(metadataReader.getClassMetadata().getClassName()));
			}
		}
	}
	return candidates;
}
 
開發者ID:namics,項目名稱:spring-batch-support,代碼行數:19,代碼來源:AutomaticJobRegistrarConfigurationSupport.java

示例4: findMangoDaoClasses

import org.springframework.core.io.support.ResourcePatternResolver; //導入方法依賴的package包/類
private List<Class<?>> findMangoDaoClasses(String packages) {
    try {
        List<Class<?>> daos = new ArrayList<Class<?>>();
        ResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver();
        MetadataReaderFactory metadataReaderFactory = new CachingMetadataReaderFactory(resourcePatternResolver);
        for (String locationPattern : getLocationPattern(packages)) {
            Resource[] rs = resourcePatternResolver.getResources(locationPattern);
            for (Resource r : rs) {
                MetadataReader reader = metadataReaderFactory.getMetadataReader(r);
                AnnotationMetadata annotationMD = reader.getAnnotationMetadata();
                if (annotationMD.hasAnnotation(DB.class.getName())) {
                    ClassMetadata clazzMD = reader.getClassMetadata();
                    daos.add(Class.forName(clazzMD.getClassName()));
                }
            }
        }
        return daos;
    } catch (Exception e) {
        throw new IllegalStateException(e.getMessage(), e);
    }
}
 
開發者ID:jfaster,項目名稱:mango-spring-boot-starter,代碼行數:22,代碼來源:MangoDaoAutoCreator.java

示例5: getSqlSessionFactory

import org.springframework.core.io.support.ResourcePatternResolver; //導入方法依賴的package包/類
@Bean
@Primary
public SqlSessionFactoryBean getSqlSessionFactory() throws IOException {
    SqlSessionFactoryBean bean = new SqlSessionFactoryBean();

    ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    Resource[] resources = resolver.getResources("classpath*:/mapper/*.xml");

    bean.setMapperLocations(resources);
    bean.setDataSource(multipleDataSource);
    return bean;
}
 
開發者ID:Wangzr,項目名稱:micro-service-framework,代碼行數:13,代碼來源:WebConfiguration.java

示例6: findPackage

import org.springframework.core.io.support.ResourcePatternResolver; //導入方法依賴的package包/類
private Package findPackage(CharSequence source) {
	Package pkg = Package.getPackage(source.toString());
	if (pkg != null) {
		return pkg;
	}
	try {
		// Attempt to find a class in this package
		ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(
				getClass().getClassLoader());
		Resource[] resources = resolver.getResources(
				ClassUtils.convertClassNameToResourcePath(source.toString())
						+ "/*.class");
		for (Resource resource : resources) {
			String className = StringUtils
					.stripFilenameExtension(resource.getFilename());
			load(Class.forName(source.toString() + "." + className));
			break;
		}
	}
	catch (Exception ex) {
		// swallow exception and continue
	}
	return Package.getPackage(source.toString());
}
 
開發者ID:philwebb,項目名稱:spring-boot-concourse,代碼行數:25,代碼來源:BeanDefinitionLoader.java

示例7: anyExists

import org.springframework.core.io.support.ResourcePatternResolver; //導入方法依賴的package包/類
private boolean anyExists(ResourcePatternResolver resolver) throws IOException {
	String searchPath = this.path;
	if (searchPath.startsWith(ResourceLoader.CLASSPATH_URL_PREFIX)) {
		searchPath = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX
				+ searchPath.substring(ResourceLoader.CLASSPATH_URL_PREFIX.length());
	}
	if (searchPath.startsWith(ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX)) {
		Resource[] resources = resolver.getResources(searchPath);
		for (Resource resource : resources) {
			if (resource.exists()) {
				return true;
			}
		}
	}
	return false;
}
 
開發者ID:philwebb,項目名稱:spring-boot-concourse,代碼行數:17,代碼來源:TemplateLocation.java

示例8: testNoRootCpBundleResourceNestedInClassPathFound

import org.springframework.core.io.support.ResourcePatternResolver; //導入方法依賴的package包/類
public void testNoRootCpBundleResourceNestedInClassPathFound() throws Exception {
	ResourcePatternResolver resolver = getNoRootCpBundleResourceResolver();
	Resource[] res = resolver.getResources("classpath*:/some/nested/nested.file");
	assertFalse("resource should be found since it's on the classpath", ObjectUtils.isEmpty(res));
	assertTrue("resource should be found since it's on the classpath", res[0].exists());
	System.out.println("classpath*:/some/nested/nested.file resources");
	printPathWithinContext(res);
}
 
開發者ID:eclipse,項目名稱:gemini.blueprint,代碼行數:9,代碼來源:BundleClassPathWildcardTest.java

示例9: findValidBlueprintConfigs

import org.springframework.core.io.support.ResourcePatternResolver; //導入方法依賴的package包/類
/**
 * Checks if the given bundle contains existing configurations. The absolute paths are returned without performing
 * any checks.
 * 
 * @return
 */
private String[] findValidBlueprintConfigs(Bundle bundle, String[] locations) {
	List<String> configs = new ArrayList<String>(locations.length);
	ResourcePatternResolver loader = new OsgiBundleResourcePatternResolver(bundle);

	boolean debug = log.isDebugEnabled();
	for (String location : locations) {
		if (isAbsolute(location)) {
			configs.add(location);
		}
		// resolve the location to check if it's present
		else {
			try {
				String loc = location;
				if (loc.endsWith("/")) {
					loc = loc + "*.xml";
				}
				Resource[] resources = loader.getResources(loc);
				if (!ObjectUtils.isEmpty(resources)) {
					for (Resource resource : resources) {
						if (resource.exists()) {
							String value = resource.getURL().toString();
							if (debug)
								log.debug("Found location " + value);
							configs.add(value);
						}
					}
				}
			} catch (IOException ex) {
				if (debug)
					log.debug("Cannot resolve location " + location, ex);
			}
		}
	}
	return (String[]) configs.toArray(new String[configs.size()]);
}
 
開發者ID:eclipse,項目名稱:gemini.blueprint,代碼行數:42,代碼來源:BlueprintConfigurationScanner.java

示例10: resolveMapperLocations

import org.springframework.core.io.support.ResourcePatternResolver; //導入方法依賴的package包/類
public Resource[] resolveMapperLocations() {
  ResourcePatternResolver resourceResolver = new PathMatchingResourcePatternResolver();
  List<Resource> resources = new ArrayList<Resource>();
  if (this.mapperLocations != null) {
    for (String mapperLocation : this.mapperLocations) {
      try {
        Resource[] mappers = resourceResolver.getResources(mapperLocation);
        resources.addAll(Arrays.asList(mappers));
      } catch (IOException e) {
        // ignore
      }
    }
  }
  return resources.toArray(new Resource[resources.size()]);
}
 
開發者ID:abel533,項目名稱:mapper-boot-starter,代碼行數:16,代碼來源:MybatisProperties.java

示例11: findPackageClass

import org.springframework.core.io.support.ResourcePatternResolver; //導入方法依賴的package包/類
/**
 * 根據掃描包的,查詢下麵的所有類
 *
 * @param scanPackages
 *            掃描的package路徑
 * @return
 */
public static Set<String> findPackageClass(String scanPackages) {
    if (StringUtils.isBlank(scanPackages)) {
        return Collections.emptySet();
    }
    // 驗證及排重包路徑,避免父子路徑多次掃描
    Set<String> packages = checkPackage(scanPackages);
    ResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver();
    MetadataReaderFactory metadataReaderFactory =
            new CachingMetadataReaderFactory(resourcePatternResolver);
    Set<String> clazzSet = new HashSet<String>();
    for (String basePackage : packages) {
        if (StringUtils.isBlank(basePackage)) {
            continue;
        }
        String packageSearchPath = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX
                + org.springframework.util.ClassUtils
                    .convertClassNameToResourcePath(SystemPropertyUtils.resolvePlaceholders(basePackage))
                + "/" + DEFAULT_RESOURCE_PATTERN;
        try {
            Resource[] resources = resourcePatternResolver.getResources(packageSearchPath);
            for (Resource resource : resources) {
                // 檢查resource,這裏的resource都是class
                String clazz = loadClassName(metadataReaderFactory, resource);
                clazzSet.add(clazz);
            }
        }
        catch (Exception e) {
            log.error("獲取包內shard方法失敗,package:" + basePackage, e);
        }
    }
    return clazzSet;
}
 
開發者ID:devpage,項目名稱:sharding-quickstart,代碼行數:40,代碼來源:PackageUtil.java

示例12: testNoRootCpBundleResourceInRootNotFound

import org.springframework.core.io.support.ResourcePatternResolver; //導入方法依賴的package包/類
public void testNoRootCpBundleResourceInRootNotFound() throws Exception {
	ResourcePatternResolver resolver = getNoRootCpBundleResourceResolver();
	Resource[] res = resolver.getResources("classpath:root.file");
	// since there is no pattern matching, the loader will return a non-existing resource
	assertFalse("resource should not be found since / is not in the classpath", res[0].exists());
	System.out.println("classpath:root.file resources");
	printPathWithinContext(res);
}
 
開發者ID:eclipse,項目名稱:gemini.blueprint,代碼行數:9,代碼來源:BundleClassPathWildcardTest.java

示例13: testNoRootCpBundleResourceInRootNotFoundOnAllClasspaths

import org.springframework.core.io.support.ResourcePatternResolver; //導入方法依賴的package包/類
public void testNoRootCpBundleResourceInRootNotFoundOnAllClasspaths() throws Exception {
	ResourcePatternResolver resolver = getNoRootCpBundleResourceResolver();
	Resource[] res = resolver.getResources("classpath*:root.file");
	assertTrue("resource should not be found since / is not in the classpath", ObjectUtils.isEmpty(res));
	System.out.println("root.file resources");
	System.out.println("classpath*:root.file resources");
	printPathWithinContext(res);
}
 
開發者ID:eclipse,項目名稱:gemini.blueprint,代碼行數:9,代碼來源:BundleClassPathWildcardTest.java

示例14: testNoRootCpBundleResourceInClassPathFound

import org.springframework.core.io.support.ResourcePatternResolver; //導入方法依賴的package包/類
public void testNoRootCpBundleResourceInClassPathFound() throws Exception {
	ResourcePatternResolver resolver = getNoRootCpBundleResourceResolver();
	Resource[] res = resolver.getResources("classpath*:cp.file");
	assertFalse("resource should be found since it's on the classpath", ObjectUtils.isEmpty(res));
	assertTrue("resource should be found since it's on the classpath", res[0].exists());
	System.out.println("classpath*:cp.file resources");
	printPathWithinContext(res);
}
 
開發者ID:eclipse,項目名稱:gemini.blueprint,代碼行數:9,代碼來源:BundleClassPathWildcardTest.java

示例15: resolveMapperLocations

import org.springframework.core.io.support.ResourcePatternResolver; //導入方法依賴的package包/類
public Resource[] resolveMapperLocations() {
	ResourcePatternResolver resourceResolver = new PathMatchingResourcePatternResolver();
	List<Resource> resources = new ArrayList<Resource>();
	if (this.mapperLocations != null) {
		for (String mapperLocation : this.mapperLocations) {
			try {
				Resource[] mappers = resourceResolver.getResources(mapperLocation);
				resources.addAll(Arrays.asList(mappers));
			} catch (IOException e) {
				// ignore
			}
		}
	}
	return resources.toArray(new Resource[resources.size()]);
}
 
開發者ID:whatlookingfor,項目名稱:spring-boot-sample,代碼行數:16,代碼來源:MybatisProperties.java


注:本文中的org.springframework.core.io.support.ResourcePatternResolver.getResources方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。