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

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

Introduction

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

Prototype

public synchronized Throwable getCause() 

Source Link

Document

Returns the cause of this throwable or null if the cause is nonexistent or unknown.

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.
 *///from  ww w .ja  v a 2 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);
    }
}