Example usage for org.springframework.beans.factory BeanNotOfRequiredTypeException getBeanName

List of usage examples for org.springframework.beans.factory BeanNotOfRequiredTypeException getBeanName

Introduction

In this page you can find the example usage for org.springframework.beans.factory BeanNotOfRequiredTypeException getBeanName.

Prototype

public String getBeanName() 

Source Link

Document

Return the name of the instance that was of the wrong type.

Usage

From source file:com.griddynamics.banshun.RegistryBeanTest.java

@Test
public void importBeanWithSubclass() {
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(
            "com/griddynamics/banshun/registry/illegal-concrete-import.xml");

    assertTrue("have no exports due to laziness", hasNoExports(ctx));
    Object proxy = ctx.getBean("early-import");

    // force export
    ctx.getBean("export-declaration");

    try {/*from  w  ww .j av  a2 s  . co m*/
        // target is ready here, but types does not match
        proxy.toString();
    } catch (BeanNotOfRequiredTypeException e) {
        assertEquals("just-bean", e.getBeanName());

        try {
            Object b = ctx.getBean("late-import").toString();
            b.toString();
        } catch (BeansException e2) {
            assertEquals("just-bean", ((BeanNotOfRequiredTypeException) e2).getBeanName());
            return;
        }

        fail("we should have BeanCreactionException here");
        return;
    }
    fail("we should have BeanNotOfRequiredTypeException here");
}