Search in sources :

Example 31 with XmlBeanDefinitionReader

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

the class CamelContextFactoryBeanTest method testGenericApplicationContextUsingNamespaces.

public void testGenericApplicationContextUsingNamespaces() throws Exception {
    applicationContext = new GenericApplicationContext();
    XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader((BeanDefinitionRegistry) applicationContext);
    xmlReader.loadBeanDefinitions(new ClassPathResource("org/apache/camel/spring/camelContextFactoryBean.xml"));
    // lets refresh to inject the applicationContext into beans
    applicationContext.refresh();
    CamelContext context = applicationContext.getBean("camel3", CamelContext.class);
    assertValidContext(context);
}
Also used : CamelContext(org.apache.camel.CamelContext) SpringCamelContext(org.apache.camel.spring.SpringCamelContext) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) ClassPathResource(org.springframework.core.io.ClassPathResource)

Example 32 with XmlBeanDefinitionReader

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

the class BlueprintNamespaceHandler method createSpringParserContext.

private org.springframework.beans.factory.xml.ParserContext createSpringParserContext(ParserContext parserContext, DefaultListableBeanFactory registry) {
    try {
        XmlBeanDefinitionReader xbdr = new XmlBeanDefinitionReader(registry);
        Resource resource = new UrlResource(parserContext.getSourceNode().getOwnerDocument().getDocumentURI());
        ProblemReporter problemReporter = new FailFastProblemReporter();
        ReaderEventListener listener = new EmptyReaderEventListener();
        SourceExtractor extractor = new NullSourceExtractor();
        NamespaceHandlerResolver resolver = new SpringNamespaceHandlerResolver(parserContext);
        xbdr.setProblemReporter(problemReporter);
        xbdr.setEventListener(listener);
        xbdr.setSourceExtractor(extractor);
        xbdr.setNamespaceHandlerResolver(resolver);
        XmlReaderContext xmlReaderContext = xbdr.createReaderContext(resource);
        BeanDefinitionParserDelegate bdpd = new BeanDefinitionParserDelegate(xmlReaderContext);
        return new org.springframework.beans.factory.xml.ParserContext(xmlReaderContext, bdpd);
    } catch (Exception e) {
        throw new RuntimeException("Error creating spring parser context", e);
    }
}
Also used : EmptyReaderEventListener(org.springframework.beans.factory.parsing.EmptyReaderEventListener) ProblemReporter(org.springframework.beans.factory.parsing.ProblemReporter) FailFastProblemReporter(org.springframework.beans.factory.parsing.FailFastProblemReporter) NamespaceHandlerResolver(org.springframework.beans.factory.xml.NamespaceHandlerResolver) BeanDefinitionParserDelegate(org.springframework.beans.factory.xml.BeanDefinitionParserDelegate) XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) UrlResource(org.springframework.core.io.UrlResource) Resource(org.springframework.core.io.Resource) ReaderEventListener(org.springframework.beans.factory.parsing.ReaderEventListener) EmptyReaderEventListener(org.springframework.beans.factory.parsing.EmptyReaderEventListener) XmlReaderContext(org.springframework.beans.factory.xml.XmlReaderContext) FailFastProblemReporter(org.springframework.beans.factory.parsing.FailFastProblemReporter) UrlResource(org.springframework.core.io.UrlResource) ParserContext(org.apache.aries.blueprint.ParserContext) NullSourceExtractor(org.springframework.beans.factory.parsing.NullSourceExtractor) SourceExtractor(org.springframework.beans.factory.parsing.SourceExtractor) NullSourceExtractor(org.springframework.beans.factory.parsing.NullSourceExtractor)

Example 33 with XmlBeanDefinitionReader

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

the class XmlWebApplicationContext method loadBeanDefinitions.

/**
	 * Loads the bean definitions via an XmlBeanDefinitionReader.
	 * @see org.springframework.beans.factory.xml.XmlBeanDefinitionReader
	 * @see #initBeanDefinitionReader
	 * @see #loadBeanDefinitions
	 */
@Override
protected void loadBeanDefinitions(DefaultListableBeanFactory beanFactory) throws BeansException, IOException {
    // Create a new XmlBeanDefinitionReader for the given BeanFactory.
    XmlBeanDefinitionReader beanDefinitionReader = new XmlBeanDefinitionReader(beanFactory);
    // Configure the bean definition reader with this context's
    // resource loading environment.
    beanDefinitionReader.setEnvironment(getEnvironment());
    beanDefinitionReader.setResourceLoader(this);
    beanDefinitionReader.setEntityResolver(new ResourceEntityResolver(this));
    // Allow a subclass to provide custom initialization of the reader,
    // then proceed with actually loading the bean definitions.
    initBeanDefinitionReader(beanDefinitionReader);
    loadBeanDefinitions(beanDefinitionReader);
}
Also used : XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) ResourceEntityResolver(org.springframework.beans.factory.xml.ResourceEntityResolver)

Example 34 with XmlBeanDefinitionReader

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

the class SessionScopeTests method setup.

@Before
public void setup() throws Exception {
    this.beanFactory.registerScope("session", new SessionScope());
    XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(this.beanFactory);
    reader.loadBeanDefinitions(new ClassPathResource("sessionScopeTests.xml", getClass()));
}
Also used : XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) ClassPathResource(org.springframework.core.io.ClassPathResource) Before(org.junit.Before)

Example 35 with XmlBeanDefinitionReader

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

the class BeanFactoryTransactionTests method testNoTransactionAttributeSource.

/**
	 * Check that we fail gracefully if the user doesn't set any transaction attributes.
	 */
@Test
public void testNoTransactionAttributeSource() {
    try {
        DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
        new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource("noTransactionAttributeSource.xml", getClass()));
        bf.getBean("noTransactionAttributeSource");
        fail("Should require TransactionAttributeSource to be set");
    } catch (FatalBeanException ex) {
    // Ok
    }
}
Also used : XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) FatalBeanException(org.springframework.beans.FatalBeanException) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

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