List of usage examples for org.springframework.beans.factory.support AbstractBeanDefinition getScope
@Override
@Nullable
public String getScope()
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()); }