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


Java ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX屬性代碼示例

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


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

示例1: findMyTypes

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,代碼行數:18,代碼來源:AutomaticJobRegistrarConfigurationSupport.java

示例2: getClassSet

/**
 * 將符合條件的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,代碼行數:28,代碼來源:ClasspathPackageScanner.java

示例3: createSqlSessionFactoryBean

@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,代碼行數:20,代碼來源:MyBatisConfig.java

示例4: getInstance

/**
 * Returns an instance which uses the the specified selector, as the name of the
 * definition file(s). In the case of a name with a Spring "classpath*:" prefix,
 * or with no prefix, which is treated the same, the current thread's context class
 * loader's {@code getResources} method will be called with this value to get
 * all resources having that name. These resources will then be combined to form a
 * definition. In the case where the name uses a Spring "classpath:" prefix, or
 * a standard URL prefix, then only one resource file will be loaded as the
 * definition.
 * @param selector the location of the resource(s) which will be read and
 * combined to form the definition for the BeanFactoryLocator instance.
 * Any such files must form a valid ApplicationContext definition.
 * @return the corresponding BeanFactoryLocator instance
 * @throws BeansException in case of factory loading failure
 */
public static BeanFactoryLocator getInstance(String selector) throws BeansException {
	String resourceLocation = selector;
	if (resourceLocation == null) {
		resourceLocation = DEFAULT_RESOURCE_LOCATION;
	}

	// For backwards compatibility, we prepend "classpath*:" to the selector name if there
	// is no other prefix (i.e. "classpath*:", "classpath:", or some URL prefix).
	if (!ResourcePatternUtils.isUrl(resourceLocation)) {
		resourceLocation = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + resourceLocation;
	}

	synchronized (instances) {
		if (logger.isTraceEnabled()) {
			logger.trace("ContextSingletonBeanFactoryLocator.getInstance(): instances.hashCode=" +
					instances.hashCode() + ", instances=" + instances);
		}
		BeanFactoryLocator bfl = instances.get(resourceLocation);
		if (bfl == null) {
			bfl = new ContextSingletonBeanFactoryLocator(resourceLocation);
			instances.put(resourceLocation, bfl);
		}
		return bfl;
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:40,代碼來源:ContextSingletonBeanFactoryLocator.java

示例5: getInstance

/**
 * Returns an instance which uses the the specified selector, as the name of the
 * definition file(s). In the case of a name with a Spring 'classpath*:' prefix,
 * or with no prefix, which is treated the same, the current thread context
 * ClassLoader's {@code getResources} method will be called with this value
 * to get all resources having that name. These resources will then be combined to
 * form a definition. In the case where the name uses a Spring 'classpath:' prefix,
 * or a standard URL prefix, then only one resource file will be loaded as the
 * definition.
 * @param selector the name of the resource(s) which will be read and
 * combined to form the definition for the BeanFactoryLocator instance.
 * Any such files must form a valid BeanFactory definition.
 * @return the corresponding BeanFactoryLocator instance
 * @throws BeansException in case of factory loading failure
 */
public static BeanFactoryLocator getInstance(String selector) throws BeansException {
	String resourceLocation = selector;
	if (resourceLocation == null) {
		resourceLocation = DEFAULT_RESOURCE_LOCATION;
	}

	// For backwards compatibility, we prepend 'classpath*:' to the selector name if there
	// is no other prefix (i.e. classpath*:, classpath:, or some URL prefix.
	if (!ResourcePatternUtils.isUrl(resourceLocation)) {
		resourceLocation = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + resourceLocation;
	}

	synchronized (instances) {
		if (logger.isTraceEnabled()) {
			logger.trace("SingletonBeanFactoryLocator.getInstance(): instances.hashCode=" +
					instances.hashCode() + ", instances=" + instances);
		}
		BeanFactoryLocator bfl = instances.get(resourceLocation);
		if (bfl == null) {
			bfl = new SingletonBeanFactoryLocator(resourceLocation);
			instances.put(resourceLocation, bfl);
		}
		return bfl;
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:40,代碼來源:SingletonBeanFactoryLocator.java

示例6: scan

/**
 * 將符合條件的Bean以Class集合的形式返回
 * @throws Exception 異常
 * @return 類集合
 */
public Set<Class<?>> scan() throws Exception {
	Set<Class<?>> classSet = new HashSet<Class<?>>();
	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)) {
						classSet.add(Class.forName(className));
					}
				}
			}
		}
	}
	return classSet;
}
 
開發者ID:yaoakeji,項目名稱:hibatis,代碼行數:26,代碼來源:ClassScanner.java

示例7: createSqlSessionFactoryBean

protected final AbstractBeanDefinition createSqlSessionFactoryBean(String dataSourceName, String mapperPackage,
		String typeAliasesPackage, Dialect dialect, Configuration configuration) {
	configuration.setDatabaseId(dataSourceName);
	BeanDefinitionBuilder bdb = BeanDefinitionBuilder.rootBeanDefinition(SqlSessionFactoryBean.class);
	bdb.addPropertyValue("configuration", configuration);
	bdb.addPropertyValue("failFast", true);
	bdb.addPropertyValue("typeAliases", this.saenTypeAliases(typeAliasesPackage));
	bdb.addPropertyReference("dataSource", dataSourceName);
	bdb.addPropertyValue("plugins", new Interceptor[] { new CustomPageInterceptor(dialect) });
	if (!StringUtils.isEmpty(mapperPackage)) {
		try {
			mapperPackage = new StandardEnvironment().resolveRequiredPlaceholders(mapperPackage);
			String mapperPackages = ClassUtils.convertClassNameToResourcePath(mapperPackage);
			String mapperPackagePath = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + mapperPackages + "/*.xml";
			Resource[] resources = new PathMatchingResourcePatternResolver().getResources(mapperPackagePath);
			bdb.addPropertyValue("mapperLocations", resources);
		} catch (Exception e) {
			log.error("初始化失敗", e);
			throw new RuntimeException( String.format("SqlSessionFactory 初始化失敗  mapperPackage=%s", mapperPackage + ""));
		}
	}
	return bdb.getBeanDefinition();
}
 
開發者ID:halober,項目名稱:spring-boot-starter-dao,代碼行數:23,代碼來源:AbstractDataBaseBean.java

示例8: findInterestResources

public List<Resource> findInterestResources(String basePackage) {
String[] packages = StringUtils.tokenizeToStringArray(basePackage,
	ConfigurableApplicationContext.CONFIG_LOCATION_DELIMITERS);
List<Resource> allResource = new LinkedList<Resource>();
try {
    for (String pack : packages) {
	String packageSearchPath = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + resolveBasePackage(pack)
		+ "/" + this.resourcePattern;
	Resource[] resources = this.resourcePatternResolver.getResources(packageSearchPath);
	allResource.addAll(Arrays.asList(resources));
    }
} catch (IOException ex) {
    throw new BeanDefinitionStoreException("掃描ClassPath的時候I/O資源錯誤", ex);
}
return allResource;
   }
 
開發者ID:ilivoo,項目名稱:game,代碼行數:16,代碼來源:ClassPathClassScanner.java

示例9: doScanExtension

public synchronized void doScanExtension() {
    if(SCANNED){
        return;
    }
    SCANNED = true;
    try {
        String packageSearchPath = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + "/META-INF/venus.exception.xml";
        Resource[] resources = resourcePatternResolver.getResources(packageSearchPath);
        for (Resource resource : resources) {
            if (logger.isInfoEnabled()) {
                logger.info("Scanning " + resource);
            }
            if (resource.isReadable()) {
                load(resource);
            } else {
                if (logger.isInfoEnabled()) {
                    logger.info("Ignored because not readable: " + resource);
                }
            }
        }
    } catch (IOException ex) {
        logger.error("read venus exception xml error", ex);
    }
    
}
 
開發者ID:blusechen,項目名稱:venus,代碼行數:25,代碼來源:XmlVenusExceptionFactory.java

示例10: getInstance

/**
 * Returns an instance which uses the specified selector, as the name of the
 * definition file(s). In the case of a name with a Spring "classpath*:" prefix,
 * or with no prefix, which is treated the same, the current thread's context class
 * loader's {@code getResources} method will be called with this value to get
 * all resources having that name. These resources will then be combined to form a
 * definition. In the case where the name uses a Spring "classpath:" prefix, or
 * a standard URL prefix, then only one resource file will be loaded as the
 * definition.
 * @param selector the location of the resource(s) which will be read and
 * combined to form the definition for the BeanFactoryLocator instance.
 * Any such files must form a valid ApplicationContext definition.
 * @return the corresponding BeanFactoryLocator instance
 * @throws BeansException in case of factory loading failure
 */
public static BeanFactoryLocator getInstance(String selector) throws BeansException {
	String resourceLocation = selector;
	if (resourceLocation == null) {
		resourceLocation = DEFAULT_RESOURCE_LOCATION;
	}

	// For backwards compatibility, we prepend "classpath*:" to the selector name if there
	// is no other prefix (i.e. "classpath*:", "classpath:", or some URL prefix).
	if (!ResourcePatternUtils.isUrl(resourceLocation)) {
		resourceLocation = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + resourceLocation;
	}

	synchronized (instances) {
		if (logger.isTraceEnabled()) {
			logger.trace("ContextSingletonBeanFactoryLocator.getInstance(): instances.hashCode=" +
					instances.hashCode() + ", instances=" + instances);
		}
		BeanFactoryLocator bfl = instances.get(resourceLocation);
		if (bfl == null) {
			bfl = new ContextSingletonBeanFactoryLocator(resourceLocation);
			instances.put(resourceLocation, bfl);
		}
		return bfl;
	}
}
 
開發者ID:txazo,項目名稱:spring,代碼行數:40,代碼來源:ContextSingletonBeanFactoryLocator.java

示例11: getInstance

/**
 * Returns an instance which uses the specified selector, as the name of the
 * definition file(s). In the case of a name with a Spring 'classpath*:' prefix,
 * or with no prefix, which is treated the same, the current thread context
 * ClassLoader's {@code getResources} method will be called with this value
 * to get all resources having that name. These resources will then be combined to
 * form a definition. In the case where the name uses a Spring 'classpath:' prefix,
 * or a standard URL prefix, then only one resource file will be loaded as the
 * definition.
 * @param selector the name of the resource(s) which will be read and
 * combined to form the definition for the BeanFactoryLocator instance.
 * Any such files must form a valid BeanFactory definition.
 * @return the corresponding BeanFactoryLocator instance
 * @throws BeansException in case of factory loading failure
 */
public static BeanFactoryLocator getInstance(String selector) throws BeansException {
	String resourceLocation = selector;
	if (resourceLocation == null) {
		resourceLocation = DEFAULT_RESOURCE_LOCATION;
	}

	// For backwards compatibility, we prepend 'classpath*:' to the selector name if there
	// is no other prefix (i.e. classpath*:, classpath:, or some URL prefix.
	if (!ResourcePatternUtils.isUrl(resourceLocation)) {
		resourceLocation = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + resourceLocation;
	}

	synchronized (instances) {
		if (logger.isTraceEnabled()) {
			logger.trace("SingletonBeanFactoryLocator.getInstance(): instances.hashCode=" +
					instances.hashCode() + ", instances=" + instances);
		}
		BeanFactoryLocator bfl = instances.get(resourceLocation);
		if (bfl == null) {
			bfl = new SingletonBeanFactoryLocator(resourceLocation);
			instances.put(resourceLocation, bfl);
		}
		return bfl;
	}
}
 
開發者ID:txazo,項目名稱:spring,代碼行數:40,代碼來源:SingletonBeanFactoryLocator.java

示例12: convertTypeAliasesPackage

/**
   * <p>
   * 別名通配符設置
   * </p>
   * <p>
   * <property name="typeAliasesPackage" value="com.baomidou.*.entity"/>
   * </p>
   *
   * @param typeAliasesPackage 類別名包路徑
   * @return
   */
  public static String[] convertTypeAliasesPackage(String typeAliasesPackage) {
      ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
      MetadataReaderFactory metadataReaderFactory = new CachingMetadataReaderFactory(resolver);
      String pkg = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX
              + ClassUtils.convertClassNameToResourcePath(typeAliasesPackage) + "/*.class";

/*
       * 將加載多個絕對匹配的所有Resource
 * 將首先通過ClassLoader.getResource("META-INF")加載非模式路徑部分,然後進行遍曆模式匹配,排除重複包路徑
 */
      try {
          Set<String> set = new HashSet<>();
          Resource[] resources = resolver.getResources(pkg);
          if (resources != null && resources.length > 0) {
              MetadataReader metadataReader;
              for (Resource resource : resources) {
                  if (resource.isReadable()) {
                      metadataReader = metadataReaderFactory.getMetadataReader(resource);
                      set.add(Class.forName(metadataReader.getClassMetadata().getClassName()).getPackage().getName());
                  }
              }
          }
          if (!set.isEmpty()) {
              return set.toArray(new String[]{});
          } else {
              throw new MybatisPlusException("not find typeAliasesPackage:" + pkg);
          }
      } catch (Exception e) {
          throw new MybatisPlusException("not find typeAliasesPackage:" + pkg, e);
      }
  }
 
開發者ID:Caratacus,項目名稱:mybatis-plus-mini,代碼行數:42,代碼來源:PackageHelper.java

示例13: findPackageClass

/**
 * 根據掃描包的,查詢下麵的所有類
 *
 * @param scanPackages 掃描的package路徑
 * @return
 */
public static Set<String> findPackageClass(String scanPackages)
{
	if (StringUtils.isEmpty(scanPackages))
	{
		return Collections.EMPTY_SET;
	}
	//驗證及排重包路徑,避免父子路徑多次掃描
	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.isEmpty(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("獲取包下麵的類信息失敗,package:" + basePackage, e);
		}

	}
	return clazzSet;
}
 
開發者ID:netease-lede,項目名稱:rocketmq-easyclient,代碼行數:45,代碼來源:ScanPackage.java

示例14: findPackageClass

/**
 * 根據掃描包的,查詢下麵的所有類
 *
 * @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,代碼行數:39,代碼來源:PackageUtil.java

示例15: getClassSearchPattern

private static String getClassSearchPattern(String packageName) {
    String resolvedPackageName = SystemPropertyUtils.resolvePlaceholders(packageName);
    String resourcePath = ClassUtils.convertClassNameToResourcePath(resolvedPackageName);

    if (StringUtils.isEmpty(resourcePath)) {
        return ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + "??/" + CLASS_RESOURCE_PATTERN;
    }

    return ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + resourcePath + "/" + CLASS_RESOURCE_PATTERN;
}
 
開發者ID:Indoqa,項目名稱:indoqa-spring,代碼行數:10,代碼來源:ClassPathScanner.java


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