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