Example usage for org.springframework.context.index CandidateComponentsIndex CandidateComponentsIndex

List of usage examples for org.springframework.context.index CandidateComponentsIndex CandidateComponentsIndex

Introduction

In this page you can find the example usage for org.springframework.context.index CandidateComponentsIndex CandidateComponentsIndex.

Prototype

CandidateComponentsIndex(List<Properties> content) 

Source Link

Usage

From source file:org.springframework.context.index.CandidateComponentsIndexLoader.java

@Nullable
private static CandidateComponentsIndex doLoadIndex(ClassLoader classLoader) {
    if (shouldIgnoreIndex) {
        return null;
    }//www .j a v a  2 s  .  co  m

    try {
        Enumeration<URL> urls = classLoader.getResources(COMPONENTS_RESOURCE_LOCATION);
        if (!urls.hasMoreElements()) {
            return null;
        }
        List<Properties> result = new ArrayList<>();
        while (urls.hasMoreElements()) {
            URL url = urls.nextElement();
            Properties properties = PropertiesLoaderUtils.loadProperties(new UrlResource(url));
            result.add(properties);
        }
        if (logger.isDebugEnabled()) {
            logger.debug("Loaded " + result.size() + "] index(es)");
        }
        int totalCount = result.stream().mapToInt(Properties::size).sum();
        return (totalCount > 0 ? new CandidateComponentsIndex(result) : null);
    } catch (IOException ex) {
        throw new IllegalStateException(
                "Unable to load indexes from location [" + COMPONENTS_RESOURCE_LOCATION + "]", ex);
    }
}