Search in sources :

Example 61 with XmlBeanDefinitionReader

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

the class JeeNamespaceHandlerTests method setUp.

@Before
public void setUp() throws Exception {
    GenericApplicationContext ctx = new GenericApplicationContext();
    new XmlBeanDefinitionReader(ctx).loadBeanDefinitions(new ClassPathResource("jeeNamespaceHandlerTests.xml", getClass()));
    ctx.refresh();
    this.beanFactory = ctx.getBeanFactory();
    this.beanFactory.getBeanNamesForType(ITestBean.class);
}
Also used : GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) ClassPathResource(org.springframework.core.io.ClassPathResource) Before(org.junit.Before)

Example 62 with XmlBeanDefinitionReader

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

the class IgniteNode method loadConfiguration.

/**
 * @param springCfgPath Spring configuration file path.
 * @return Tuple with grid configuration and Spring application context.
 * @throws Exception If failed.
 */
public static IgniteBiTuple<IgniteConfiguration, ? extends ApplicationContext> loadConfiguration(String springCfgPath) throws Exception {
    URL url;
    try {
        url = new URL(springCfgPath);
    } catch (MalformedURLException e) {
        url = IgniteUtils.resolveIgniteUrl(springCfgPath);
        if (url == null)
            throw new IgniteCheckedException("Spring XML configuration path is invalid: " + springCfgPath + ". Note that this path should be either absolute or a relative local file system path, " + "relative to META-INF in classpath or valid URL to IGNITE_HOME.", e);
    }
    GenericApplicationContext springCtx;
    try {
        springCtx = new GenericApplicationContext();
        new XmlBeanDefinitionReader(springCtx).loadBeanDefinitions(new UrlResource(url));
        springCtx.refresh();
    } catch (BeansException e) {
        throw new Exception("Failed to instantiate Spring XML application context [springUrl=" + url + ", err=" + e.getMessage() + ']', e);
    }
    Map<String, IgniteConfiguration> cfgMap;
    try {
        cfgMap = springCtx.getBeansOfType(IgniteConfiguration.class);
    } catch (BeansException e) {
        throw new Exception("Failed to instantiate bean [type=" + IgniteConfiguration.class + ", err=" + e.getMessage() + ']', e);
    }
    if (cfgMap == null || cfgMap.isEmpty())
        throw new Exception("Failed to find ignite configuration in: " + url);
    return new IgniteBiTuple<>(cfgMap.values().iterator().next(), springCtx);
}
Also used : MalformedURLException(java.net.MalformedURLException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) UrlResource(org.springframework.core.io.UrlResource) IgniteBiTuple(org.apache.ignite.lang.IgniteBiTuple) XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) URL(java.net.URL) MalformedURLException(java.net.MalformedURLException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) BeansException(org.springframework.beans.BeansException) BeansException(org.springframework.beans.BeansException)

Example 63 with XmlBeanDefinitionReader

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

the class MappingMongoConverterParserIntegrationTests method rejectsInvalidFieldNamingStrategyConfiguration.

// DATAMONGO-866
@Test
public void rejectsInvalidFieldNamingStrategyConfiguration() {
    exception.expect(BeanDefinitionParsingException.class);
    exception.expectMessage("abbreviation");
    exception.expectMessage("field-naming-strategy-ref");
    BeanDefinitionRegistry factory = new DefaultListableBeanFactory();
    XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(factory);
    reader.loadBeanDefinitions(new ClassPathResource("namespace/converter-invalid.xml"));
}
Also used : XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) BeanDefinitionRegistry(org.springframework.beans.factory.support.BeanDefinitionRegistry) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Example 64 with XmlBeanDefinitionReader

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

the class MappingMongoConverterParserIntegrationTests method loadConfiguration.

private void loadConfiguration(String configLocation) {
    factory = new DefaultListableBeanFactory();
    XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(factory);
    reader.loadBeanDefinitions(new ClassPathResource(configLocation));
}
Also used : XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) ClassPathResource(org.springframework.core.io.ClassPathResource)

Example 65 with XmlBeanDefinitionReader

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

the class MappingMongoConverterParserIntegrationTests method assertStrategyReferenceSetFor.

private static void assertStrategyReferenceSetFor(String beanId) {
    BeanDefinitionRegistry factory = new DefaultListableBeanFactory();
    XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(factory);
    reader.loadBeanDefinitions(new ClassPathResource("namespace/converter-custom-fieldnamingstrategy.xml"));
    BeanDefinition definition = reader.getRegistry().getBeanDefinition(beanId.concat(".mongoMappingContext"));
    BeanReference value = (BeanReference) definition.getPropertyValues().getPropertyValue("fieldNamingStrategy").getValue();
    assertThat(value.getBeanName(), is("customFieldNamingStrategy"));
}
Also used : XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) BeanDefinitionRegistry(org.springframework.beans.factory.support.BeanDefinitionRegistry) BeanReference(org.springframework.beans.factory.config.BeanReference) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) ClassPathResource(org.springframework.core.io.ClassPathResource)

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