Example usage for org.springframework.beans.factory.support DefaultListableBeanFactory setAllowRawInjectionDespiteWrapping

List of usage examples for org.springframework.beans.factory.support DefaultListableBeanFactory setAllowRawInjectionDespiteWrapping

Introduction

In this page you can find the example usage for org.springframework.beans.factory.support DefaultListableBeanFactory setAllowRawInjectionDespiteWrapping.

Prototype

public void setAllowRawInjectionDespiteWrapping(boolean allowRawInjectionDespiteWrapping) 

Source Link

Document

Set whether to allow the raw injection of a bean instance into some other bean's property, despite the injected bean eventually getting wrapped (for example, through AOP auto-proxying).

Usage

From source file:nl.strohalm.cyclos.spring.CustomWebApplicationContext.java

@Override
protected DefaultListableBeanFactory createBeanFactory() {
    final DefaultListableBeanFactory beanFactory = super.createBeanFactory();
    beanFactory.setAllowRawInjectionDespiteWrapping(true);
    return beanFactory;
}

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

@Test
public void testCircularReferencesWithWrappingAndRawInjectionAllowed() {
    DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
    xbf.setAllowRawInjectionDespiteWrapping(true);
    XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
    reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_NONE);
    reader.loadBeanDefinitions(REFTYPES_CONTEXT);
    xbf.addBeanPostProcessor(new WrappingPostProcessor());

    ITestBean jenny = (ITestBean) xbf.getBean("jenny");
    ITestBean david = (ITestBean) xbf.getBean("david");
    assertTrue(AopUtils.isAopProxy(jenny));
    assertTrue(AopUtils.isAopProxy(david));
    assertSame(david, jenny.getSpouse());
    assertNotSame(jenny, david.getSpouse());
    assertEquals("Jenny", david.getSpouse().getName());
    assertSame(david, david.getSpouse().getSpouse());
    assertTrue(AopUtils.isAopProxy(jenny.getSpouse()));
    assertTrue(!AopUtils.isAopProxy(david.getSpouse()));
}