当前位置: 首页>>代码示例>>Java>>正文


Java ResourcePatternResolver类代码示例

本文整理汇总了Java中org.springframework.core.io.support.ResourcePatternResolver的典型用法代码示例。如果您正苦于以下问题:Java ResourcePatternResolver类的具体用法?Java ResourcePatternResolver怎么用?Java ResourcePatternResolver使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ResourcePatternResolver类属于org.springframework.core.io.support包,在下文中一共展示了ResourcePatternResolver类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getMaps

import org.springframework.core.io.support.ResourcePatternResolver; //导入依赖的package包/类
public static List<String> getMaps() {
  List<String> maps = new ArrayList<>();
  ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
  try {
    Resource[] resources = resolver.getResources("maps/*.yaml");
    Arrays.stream(resources).map(Resource::getFilename).map(f -> f.replace(".yaml", ""))
        .filter(s -> !s.equals("defaults"))
        .forEach(maps::add);
  } catch (IOException e) {
    e.printStackTrace();
  }
  File[] localYamls = new File(".").listFiles(
      (dir, name) -> name.toLowerCase().endsWith(".yaml")
  );
  Arrays.stream(localYamls).forEach(f -> maps.add(f.getName().replace(".yaml", "")));

  return maps;
}
 
开发者ID:sinaa,项目名称:train-simulator,代码行数:19,代码来源:MapBuilderHelper.java

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: getClassSet

import org.springframework.core.io.support.ResourcePatternResolver; //导入依赖的package包/类
/**
 * 将符合条件的Bean以Class集合的形式返回
 * 
 * @return
 * @throws IOException
 * @throws ClassNotFoundException
 */
public Set<Class<?>> getClassSet() throws IOException, ClassNotFoundException {
	this.classSet.clear();
	if (!this.packagesList.isEmpty()) {
		for (String pkg : this.packagesList) {
			String pattern = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX
					+ ClassUtils.convertClassNameToResourcePath(pkg) + RESOURCE_PATTERN;
			Resource[] resources = this.resourcePatternResolver.getResources(pattern);
			MetadataReaderFactory readerFactory = new CachingMetadataReaderFactory(this.resourcePatternResolver);
			for (Resource resource : resources) {
				if (resource.isReadable()) {
					MetadataReader reader = readerFactory.getMetadataReader(resource);
					String className = reader.getClassMetadata().getClassName();
					if (matchesEntityTypeFilter(reader, readerFactory)) {
						this.classSet.add(Class.forName(className));
					}
				}
			}
		}
	}
	return this.classSet;
}
 
开发者ID:jweixin,项目名称:jwx,代码行数:29,代码来源:ClasspathPackageScanner.java

示例7: testAppContextClassHierarchy

import org.springframework.core.io.support.ResourcePatternResolver; //导入依赖的package包/类
public void testAppContextClassHierarchy() {
	Class<?>[] clazz =
			ClassUtils.getClassHierarchy(OsgiBundleXmlApplicationContext.class, ClassUtils.ClassSet.ALL_CLASSES);

       //Closeable.class,
	Class<?>[] expected =
			new Class<?>[] { OsgiBundleXmlApplicationContext.class,
					AbstractDelegatedExecutionApplicationContext.class, AbstractOsgiBundleApplicationContext.class,
					AbstractRefreshableApplicationContext.class, AbstractApplicationContext.class,
					DefaultResourceLoader.class, ResourceLoader.class,
					AutoCloseable.class,
					DelegatedExecutionOsgiBundleApplicationContext.class,
					ConfigurableOsgiBundleApplicationContext.class, ConfigurableApplicationContext.class,
					ApplicationContext.class, Lifecycle.class, Closeable.class, EnvironmentCapable.class, ListableBeanFactory.class,
					HierarchicalBeanFactory.class, ApplicationEventPublisher.class, ResourcePatternResolver.class,
					MessageSource.class, BeanFactory.class, DisposableBean.class };

	assertTrue(compareArrays(expected, clazz));
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:20,代码来源:ClassUtilsTest.java

示例8: getSearchType

import org.springframework.core.io.support.ResourcePatternResolver; //导入依赖的package包/类
/**
 * Return the search type to be used for the give string based on the
 * prefix.
 * 
 * @param path
 * @return
 */
public static int getSearchType(String path) {
	Assert.notNull(path);
	int type = PREFIX_TYPE_NOT_SPECIFIED;
	String prefix = getPrefix(path);

	// no prefix is treated just like osgibundle:
	if (!StringUtils.hasText(prefix))
		type = PREFIX_TYPE_NOT_SPECIFIED;
	else if (prefix.startsWith(OsgiBundleResource.BUNDLE_URL_PREFIX))
		type = PREFIX_TYPE_BUNDLE_SPACE;
	else if (prefix.startsWith(OsgiBundleResource.BUNDLE_JAR_URL_PREFIX))
		type = PREFIX_TYPE_BUNDLE_JAR;
	else if (prefix.startsWith(ResourceLoader.CLASSPATH_URL_PREFIX))
		type = PREFIX_TYPE_CLASS_SPACE;
	else if (prefix.startsWith(ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX))
		type = PREFIX_TYPE_CLASS_ALL_SPACE;

	else
		type = PREFIX_TYPE_UNKNOWN;

	return type;
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:30,代码来源:OsgiResourceUtils.java

示例9: createSqlSessionFactoryBean

import org.springframework.core.io.support.ResourcePatternResolver; //导入依赖的package包/类
@Bean
public SqlSessionFactoryBean createSqlSessionFactoryBean() throws IOException {
    SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
    sqlSessionFactoryBean.setConfigLocation(new ClassPathResource(env.getProperty("mybatis.config-location")));
    PathMatchingResourcePatternResolver pathMatchingResourcePatternResolver = new PathMatchingResourcePatternResolver();
    String packageSearchPath = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + env.getProperty("mybatis.mapper-locations");
    sqlSessionFactoryBean.setMapperLocations(pathMatchingResourcePatternResolver.getResources(packageSearchPath));
    sqlSessionFactoryBean.setDataSource(dataSource());

    PageHelper pageHelper = new PageHelper();
    Properties properties = new Properties();
    properties.setProperty("reasonable", env.getProperty("pageHelper.reasonable"));
    properties.setProperty("supportMethodsArguments", env.getProperty("pageHelper.supportMethodsArguments"));
    properties.setProperty("returnPageInfo", env.getProperty("pageHelper.returnPageInfo"));
    properties.setProperty("params", env.getProperty("pageHelper.params"));
    pageHelper.setProperties(properties);
    sqlSessionFactoryBean.setPlugins(new Interceptor[]{pageHelper});

    return sqlSessionFactoryBean;
}
 
开发者ID:myopenresources,项目名称:cc-s,代码行数:21,代码来源:MyBatisConfig.java

示例10: setUp

import org.springframework.core.io.support.ResourcePatternResolver; //导入依赖的package包/类
@Before
public void setUp() throws IOException {
  resourceLoader =
      mock(ResourceLoader.class, withSettings().extraInterfaces(ResourcePatternResolver.class));
  elmoConfigurationResource = mock(Resource.class);
  when(elmoConfigurationResource.getFilename()).thenReturn("elmo.trig");
  elmoShapesResource = mock(Resource.class);
  // when(elmoShapesResource.getFilename()).thenReturn("elmo-shapes.trig");
  when(elmoShapesResource.getInputStream()).thenReturn(new ByteArrayInputStream(
      "@prefix dbeerpedia: <http://dbeerpedia.org#> .".getBytes(Charsets.UTF_8)));
  shaclValidator = mock(ShaclValidator.class);
  when(elmoConfigurationResource.getInputStream()).thenReturn(
      new ByteArrayInputStream("@prefix dbeerpedia: <http://dbeerpedia.org#> .".getBytes()));
  report = mock(ValidationReport.class);
  when(report.isValid()).thenReturn(true);
  when(shaclValidator.validate(any(), any())).thenReturn(report);
  backend = new FileConfigurationBackend(elmoConfigurationResource, repository, "file:config",
      elmoShapesResource, shaclValidator);
  backend.setResourceLoader(resourceLoader);
  backend.setEnvironment(environment);
  when(repository.getConnection()).thenReturn(repositoryConnection);
}
 
开发者ID:dotwebstack,项目名称:dotwebstack-framework,代码行数:23,代码来源:FileConfigurationBackendTest.java

示例11: configurateBackend_validationFailed_throwShaclValdiationException

import org.springframework.core.io.support.ResourcePatternResolver; //导入依赖的package包/类
@Test
public void configurateBackend_validationFailed_throwShaclValdiationException() throws Exception {
  // Arrange
  Resource resource = mock(Resource.class);
  when(resource.getInputStream()).thenReturn(new ByteArrayInputStream(
      "@prefix dbeerpedia: <http://dbeerpedia.org#> .".getBytes(Charsets.UTF_8)));
  when(resource.getFilename()).thenReturn("config.trig");
  when(((ResourcePatternResolver) resourceLoader).getResources(anyString())).thenReturn(
      new Resource[] {resource});
  when(report.isValid()).thenReturn(false);

  // Assert
  thrown.expect(ShaclValidationException.class);

  // Act
  backend.loadResources();
}
 
开发者ID:dotwebstack,项目名称:dotwebstack-framework,代码行数:18,代码来源:FileConfigurationBackendTest.java

示例12: loadResources_LoadsRepository_WithConfigTrigFile

import org.springframework.core.io.support.ResourcePatternResolver; //导入依赖的package包/类
@Test
public void loadResources_LoadsRepository_WithConfigTrigFile() throws Exception {
  // Arrange
  Resource resource = mock(Resource.class);
  when(resource.getInputStream()).thenReturn(new ByteArrayInputStream(
      "@prefix dbeerpedia: <http://dbeerpedia.org#> .".getBytes(Charsets.UTF_8)));
  when(resource.getFilename()).thenReturn("config.trig");
  when(((ResourcePatternResolver) resourceLoader).getResources(anyString())).thenReturn(
      new Resource[] {resource});

  // Act
  backend.loadResources();

  // Assert
  assertThat(backend.getRepository(), equalTo(repository));
  verify(repository).initialize();
  verify(repositoryConnection).close();
}
 
开发者ID:dotwebstack,项目名称:dotwebstack-framework,代码行数:19,代码来源:FileConfigurationBackendTest.java

示例13: loadResources_ThrowsException_WhenRdfDataLoadError

import org.springframework.core.io.support.ResourcePatternResolver; //导入依赖的package包/类
@Test
public void loadResources_ThrowsException_WhenRdfDataLoadError() throws Exception {
  // Arrange
  Resource resource = mock(Resource.class);
  when(resource.getInputStream()).thenThrow(new RDFParseException("message"));
  when(resource.getFilename()).thenReturn("config.trig");
  when(((ResourcePatternResolver) resourceLoader).getResources(anyString())).thenReturn(
      new Resource[] {resource});

  // Assert
  thrown.expect(ConfigurationException.class);
  thrown.expectMessage("Error while loading RDF data.");

  // Act
  backend.loadResources();
}
 
开发者ID:dotwebstack,项目名称:dotwebstack-framework,代码行数:17,代码来源:FileConfigurationBackendTest.java

示例14: loadPrefixes_ThrowConfigurationException_FoundMultiplePrefixesDeclaration

import org.springframework.core.io.support.ResourcePatternResolver; //导入依赖的package包/类
@Test
public void loadPrefixes_ThrowConfigurationException_FoundMultiplePrefixesDeclaration()
    throws Exception {
  // Arrange
  Resource resource = mock(Resource.class);
  when(resource.getInputStream()).thenReturn(
      new ByteArrayInputStream(new String("@prefix dbeerpedia: <http://dbeerpedia.org#> .\n"
          + "@prefix elmo: <http://dotwebstack.org/def/elmo#> .\n"
          + "@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .\n"
          + "@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .\n"
          + "@prefix rdfs: <http://www.have-a-nice-day.com/rdf-schema#> .").getBytes(
              Charsets.UTF_8)));
  when(resource.getFilename()).thenReturn("_prefixes.trig");
  when(((ResourcePatternResolver) resourceLoader).getResources(any())).thenReturn(
      new Resource[] {resource});

  // Assert
  thrown.expect(ConfigurationException.class);
  thrown.expectMessage(
      "Found multiple declaration <@prefix rdfs: <http://www.have-a-nice-day.com/rdf-schema#> .> at line <5>");

  // Act
  backend.loadResources();
}
 
开发者ID:dotwebstack,项目名称:dotwebstack-framework,代码行数:25,代码来源:FileConfigurationBackendTest.java

示例15: loadPrefixes_ThrowConfigurationException_FoundUnknownPrefix

import org.springframework.core.io.support.ResourcePatternResolver; //导入依赖的package包/类
@Test
public void loadPrefixes_ThrowConfigurationException_FoundUnknownPrefix() throws Exception {
  // Arrange
  Resource resource = mock(Resource.class);
  when(resource.getInputStream()).thenReturn(
      new ByteArrayInputStream(new String("@prefix dbeerpedia: <http://dbeerpedia.org#> .\n"
          + "@prefix elmo: <http://dotwebstack.org/def/elmo#> .\n"
          + "@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .\n"
          + "@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .\n"
          + "this is not a valid prefix").getBytes(Charsets.UTF_8)));
  when(resource.getFilename()).thenReturn("_prefixes.trig");
  when(((ResourcePatternResolver) resourceLoader).getResources(any())).thenReturn(
      new Resource[] {resource});

  // Assert
  thrown.expect(ConfigurationException.class);
  thrown.expectMessage("Found unknown prefix format <this is not a valid prefix> at line <5>");

  // Act
  backend.loadResources();
}
 
开发者ID:dotwebstack,项目名称:dotwebstack-framework,代码行数:22,代码来源:FileConfigurationBackendTest.java


注:本文中的org.springframework.core.io.support.ResourcePatternResolver类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。