当前位置: 首页>>代码示例>>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;未经允许,请勿转载。