Example usage for org.springframework.beans.factory.support AbstractBeanDefinition getScope

List of usage examples for org.springframework.beans.factory.support AbstractBeanDefinition getScope

Introduction

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

Prototype

@Override
@Nullable
public String getScope() 

Source Link

Document

Return the name of the target scope for the bean.

Usage

From source file:org.eclipse.gemini.blueprint.blueprint.config.internal.BlueprintParser.java

private AbstractBeanDefinition parseAttributes(Element ele, String beanName,
        AbstractBeanDefinition beanDefinition) {
    AbstractBeanDefinition bd = parserContext.getDelegate().parseBeanDefinitionAttributes(ele, beanName, null,
            beanDefinition);/*from  w w  w .  ja va 2  s.  co m*/

    // handle lazy flag (initialize)
    String lazyInit = ele.getAttribute(LAZY_INIT_ATTR);
    // check whether the value is "lazy"
    if (StringUtils.hasText(lazyInit)) {
        if (lazyInit.equalsIgnoreCase(LAZY_INIT_VALUE)) {
            bd.setLazyInit(true);
        } else {
            bd.setLazyInit(false);
        }
    } else {
        bd.setLazyInit(getDefaults(ele).getDefaultInitialization());
    }

    // handle factory component
    String componentFactory = ele.getAttribute(FACTORY_REF_ATTR);
    if (StringUtils.hasText(componentFactory)) {
        bd.setFactoryBeanName(componentFactory);
    }

    // check whether the bean is a prototype with destroy method
    if (StringUtils.hasText(bd.getDestroyMethodName())
            && BeanDefinition.SCOPE_PROTOTYPE.equalsIgnoreCase(bd.getScope())) {
        error("Blueprint prototype beans cannot define destroy methods", ele);
    }

    return bd;
}

From source file:org.springframework.beans.factory.DefaultListableBeanFactoryTests.java

@Test
public void testExplicitScopeInheritanceForChildBeanDefinitions() throws Exception {
    String theChildScope = "bonanza!";

    RootBeanDefinition parent = new RootBeanDefinition();
    parent.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);

    AbstractBeanDefinition child = BeanDefinitionBuilder.childBeanDefinition("parent").getBeanDefinition();
    child.setBeanClass(TestBean.class);
    child.setScope(theChildScope);//from   w  w w  .j  a  va  2s  .  c  om

    DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
    factory.registerBeanDefinition("parent", parent);
    factory.registerBeanDefinition("child", child);

    AbstractBeanDefinition def = (AbstractBeanDefinition) factory.getBeanDefinition("child");
    assertEquals("Child 'scope' not overriding parent scope (it must).", theChildScope, def.getScope());
}