Example usage for org.springframework.beans.factory.xml XmlBeanDefinitionReader setDocumentLoader

List of usage examples for org.springframework.beans.factory.xml XmlBeanDefinitionReader setDocumentLoader

Introduction

In this page you can find the example usage for org.springframework.beans.factory.xml XmlBeanDefinitionReader setDocumentLoader.

Prototype

public void setDocumentLoader(@Nullable DocumentLoader documentLoader) 

Source Link

Document

Specify the DocumentLoader to use.

Usage

From source file:edu.internet2.middleware.shibboleth.common.config.SpringConfigurationUtils.java

/**
 * Loads a set of spring configuration resources into a given application context.
 * /*from w w  w . j av a  2s  .co m*/
 * @param beanRegistry registry of spring beans to be populated with information from the given configurations
 * @param configurationResources list of spring configuration resources
 * 
 * @throws ResourceException thrown if there is a problem reading the spring configuration resources into the
 *             registry
 */
public static void populateRegistry(BeanDefinitionRegistry beanRegistry, List<Resource> configurationResources)
        throws ResourceException {
    XmlBeanDefinitionReader configReader = new XmlBeanDefinitionReader(beanRegistry);
    configReader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_XSD);
    configReader.setDocumentLoader(new SpringDocumentLoader());

    int numOfResources = configurationResources.size();
    Resource configurationResource;
    org.springframework.core.io.Resource[] configSources = new org.springframework.core.io.Resource[numOfResources];
    for (int i = 0; i < numOfResources; i++) {
        configurationResource = configurationResources.get(i);
        if (configurationResource != null && configurationResource.exists()) {
            configSources[i] = new InputStreamResource(configurationResources.get(i).getInputStream(),
                    configurationResource.getLocation());
        } else {
            log.warn("Configuration resource not loaded because it does not exist: {}",
                    configurationResource.getLocation());
        }
    }

    try {
        configReader.loadBeanDefinitions(configSources);
    } catch (BeanDefinitionStoreException e) {
        throw new ResourceException("Unable to load Spring bean registry with configuration resources", e);
    }
}