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

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

Introduction

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

Prototype

@Nullable
public String getResourceDescription() 

Source Link

Document

Return the description of the resource that the bean definition came from.

Usage

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

/**
 * When using a BeanFactory. singletons are of course not pre-instantiated.
 * So rubbish class names in bean defs must now not be 'resolved' when the
 * bean def is being parsed, 'cos everything on a bean def is now lazy, but
 * must rather only be picked up when the bean is instantiated.
 */// w  ww  .  j a va2  s  .c o  m
@Test
public void testClassNotFoundWithDefaultBeanClassLoader() {
    DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
    new XmlBeanDefinitionReader(factory).loadBeanDefinitions(CLASS_NOT_FOUND_CONTEXT);
    // cool, no errors, so the rubbish class name in the bean def was not resolved
    try {
        // let's resolve the bean definition; must blow up
        factory.getBean("classNotFound");
        fail("Must have thrown a CannotLoadBeanClassException");
    } catch (CannotLoadBeanClassException ex) {
        assertTrue(ex.getResourceDescription().indexOf("classNotFound.xml") != -1);
        assertTrue(ex.getCause() instanceof ClassNotFoundException);
    }
}