當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。