Search in sources :

Example 66 with XmlBeanDefinitionReader

use of org.springframework.beans.factory.xml.XmlBeanDefinitionReader in project spring-data-mongodb by spring-projects.

the class MappingMongoConverterParserValidationIntegrationTests method setUp.

@Before
public void setUp() {
    factory = new DefaultListableBeanFactory();
    reader = new XmlBeanDefinitionReader(factory);
}
Also used : XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) Before(org.junit.Before)

Example 67 with XmlBeanDefinitionReader

use of org.springframework.beans.factory.xml.XmlBeanDefinitionReader in project cxf by apache.

the class EndpointCreationLoop2 method readBeans.

private void readBeans(Resource beanResource) {
    XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(applicationContext);
    reader.loadBeanDefinitions(beanResource);
}
Also used : XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader)

Example 68 with XmlBeanDefinitionReader

use of org.springframework.beans.factory.xml.XmlBeanDefinitionReader in project engine by craftercms.

the class SiteContextFactory method getApplicationContext.

protected ConfigurableApplicationContext getApplicationContext(SiteContext siteContext, URLClassLoader classLoader, HierarchicalConfiguration config, String[] applicationContextPaths, ResourceLoader resourceLoader) {
    try {
        List<Resource> resources = new ArrayList<>();
        for (String path : applicationContextPaths) {
            Resource resource = resourceLoader.getResource(path);
            if (resource.exists()) {
                resources.add(resource);
            }
        }
        if (CollectionUtils.isNotEmpty(resources)) {
            String siteName = siteContext.getSiteName();
            logger.info("--------------------------------------------------");
            logger.info("<Loading application context for site: " + siteName + ">");
            logger.info("--------------------------------------------------");
            GenericApplicationContext appContext = new GenericApplicationContext(globalApplicationContext);
            appContext.setClassLoader(classLoader);
            if (config != null) {
                MutablePropertySources propertySources = appContext.getEnvironment().getPropertySources();
                propertySources.addFirst(new ApacheCommonsConfiguration2PropertySource("siteConfig", config));
            }
            XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(appContext);
            reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_XSD);
            for (Resource resource : resources) {
                reader.loadBeanDefinitions(resource);
            }
            appContext.refresh();
            logger.info("--------------------------------------------------");
            logger.info("</Loading application context for site: " + siteName + ">");
            logger.info("--------------------------------------------------");
            return appContext;
        } else {
            return null;
        }
    } catch (Exception e) {
        throw new SiteContextCreationException("Unable to load application context for site '" + siteContext.getSiteName() + "'", e);
    }
}
Also used : SiteContextCreationException(org.craftercms.engine.exception.SiteContextCreationException) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) Resource(org.springframework.core.io.Resource) ArrayList(java.util.ArrayList) MutablePropertySources(org.springframework.core.env.MutablePropertySources) SiteContextCreationException(org.craftercms.engine.exception.SiteContextCreationException) BeansException(org.springframework.beans.BeansException) ConfigurationException(org.apache.commons.configuration2.ex.ConfigurationException) ApacheCommonsConfiguration2PropertySource(org.craftercms.commons.spring.ApacheCommonsConfiguration2PropertySource)

Example 69 with XmlBeanDefinitionReader

use of org.springframework.beans.factory.xml.XmlBeanDefinitionReader in project cxf by apache.

the class EngineLifecycleTest method readBeans.

private void readBeans(Resource beanResource) {
    XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(applicationContext);
    reader.loadBeanDefinitions(beanResource);
}
Also used : XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader)

Example 70 with XmlBeanDefinitionReader

use of org.springframework.beans.factory.xml.XmlBeanDefinitionReader in project jetty.project by eclipse.

the class SpringConfigurationProcessor method init.

@Override
public void init(URL url, XmlParser.Node config, XmlConfiguration configuration) {
    try {
        _configuration = configuration;
        Resource resource = url != null ? new UrlResource(url) : new ByteArrayResource(("" + "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<!DOCTYPE beans PUBLIC \"-//SPRING//DTD BEAN//EN\" \"http://www.springframework.org/dtd/spring-beans.dtd\">" + config).getBytes(StandardCharsets.UTF_8));
        _beanFactory = new DefaultListableBeanFactory() {

            @Override
            protected void applyPropertyValues(String beanName, BeanDefinition mbd, BeanWrapper bw, PropertyValues pvs) {
                _configuration.initializeDefaults(bw.getWrappedInstance());
                super.applyPropertyValues(beanName, mbd, bw, pvs);
            }
        };
        new XmlBeanDefinitionReader(_beanFactory).loadBeanDefinitions(resource);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : BeanWrapper(org.springframework.beans.BeanWrapper) PropertyValues(org.springframework.beans.PropertyValues) UrlResource(org.springframework.core.io.UrlResource) XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) UrlResource(org.springframework.core.io.UrlResource) ByteArrayResource(org.springframework.core.io.ByteArrayResource) Resource(org.springframework.core.io.Resource) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) ByteArrayResource(org.springframework.core.io.ByteArrayResource) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition)

Aggregations

XmlBeanDefinitionReader (org.springframework.beans.factory.xml.XmlBeanDefinitionReader)152 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)82 Test (org.junit.Test)80 ClassPathResource (org.springframework.core.io.ClassPathResource)62 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)38 Before (org.junit.Before)30 ITestBean (org.springframework.tests.sample.beans.ITestBean)18 TestBean (org.springframework.tests.sample.beans.TestBean)11 BeansException (org.springframework.beans.BeansException)9 Resource (org.springframework.core.io.Resource)8 UrlResource (org.springframework.core.io.UrlResource)8 URL (java.net.URL)7 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)7 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)6 HashMap (java.util.HashMap)5 Person (org.springframework.tests.sample.beans.Person)5 ArrayList (java.util.ArrayList)4 BeanCreationException (org.springframework.beans.factory.BeanCreationException)4 BeanDefinitionRegistry (org.springframework.beans.factory.support.BeanDefinitionRegistry)4 ResourceEntityResolver (org.springframework.beans.factory.xml.ResourceEntityResolver)4