Example usage for org.springframework.beans.factory BeanCreationException getResourceDescription

List of usage examples for org.springframework.beans.factory BeanCreationException getResourceDescription

Introduction

In this page you can find the example usage for org.springframework.beans.factory BeanCreationException getResourceDescription.

Prototype

@Nullable
public String getResourceDescription() 

Source Link

Document

Return the description of the resource that the bean definition came from, if any.

Usage

From source file:org.springframework.beans.factory.xml.XmlBeanFactoryTests.java

/**
 * Test that if a custom initializer throws an exception, it's handled correctly
 *//*from  w  w  w.j ava  2 s .com*/
@Test
public void testInitMethodThrowsException() {
    DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
    new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(INITIALIZERS_CONTEXT);
    try {
        xbf.getBean("init-method2");
        fail();
    } catch (BeanCreationException ex) {
        assertTrue(ex.getResourceDescription().indexOf("initializers.xml") != -1);
        assertEquals("init-method2", ex.getBeanName());
        assertTrue(ex.getCause() instanceof IOException);
    }
}