Java Code Examples for org.springframework.beans.factory.support.AbstractBeanDefinition#setAutowireMode()
The following examples show how to use
org.springframework.beans.factory.support.AbstractBeanDefinition#setAutowireMode() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BeanDefinitionParserDelegate.java From spring-analysis-note with MIT License | 4 votes |
/** * Apply the attributes of the given bean element to the given bean * definition. * @param ele bean declaration element * @param beanName bean name * @param containingBean containing bean definition * @return a bean definition initialized according to the bean element attributes */ public AbstractBeanDefinition parseBeanDefinitionAttributes(Element ele, String beanName, @Nullable BeanDefinition containingBean, AbstractBeanDefinition bd) { // 注释 2.5 老版本 1.x 用的是 singleton 属性,应该升级使用 scope 属性,报错 if (ele.hasAttribute(SINGLETON_ATTRIBUTE)) { error("Old 1.x 'singleton' attribute in use - upgrade to 'scope' declaration", ele); } // 解析 scope 领域属性 else if (ele.hasAttribute(SCOPE_ATTRIBUTE)) { bd.setScope(ele.getAttribute(SCOPE_ATTRIBUTE)); } else if (containingBean != null) { // Take default from containing bean in case of an inner bean definition. // 在嵌入 beanDefinition 情况,并且没有单独指定 scope 属性,将会使用父类默认的属性 bd.setScope(containingBean.getScope()); } // 解析 abstract 属性 if (ele.hasAttribute(ABSTRACT_ATTRIBUTE)) { bd.setAbstract(TRUE_VALUE.equals(ele.getAttribute(ABSTRACT_ATTRIBUTE))); } // 是否延迟初始化,就是在第一次被调用时才进行实例化 String lazyInit = ele.getAttribute(LAZY_INIT_ATTRIBUTE); if (isDefaultValue(lazyInit)) { lazyInit = this.defaults.getLazyInit(); } bd.setLazyInit(TRUE_VALUE.equals(lazyInit)); // 解析 autowire 属性 String autowire = ele.getAttribute(AUTOWIRE_ATTRIBUTE); bd.setAutowireMode(getAutowireMode(autowire)); // 解析 depends-on 属性 if (ele.hasAttribute(DEPENDS_ON_ATTRIBUTE)) { String dependsOn = ele.getAttribute(DEPENDS_ON_ATTRIBUTE); bd.setDependsOn(StringUtils.tokenizeToStringArray(dependsOn, MULTI_VALUE_ATTRIBUTE_DELIMITERS)); } // 解析 autowire-candidate 属性 String autowireCandidate = ele.getAttribute(AUTOWIRE_CANDIDATE_ATTRIBUTE); if (isDefaultValue(autowireCandidate)) { String candidatePattern = this.defaults.getAutowireCandidates(); if (candidatePattern != null) { String[] patterns = StringUtils.commaDelimitedListToStringArray(candidatePattern); bd.setAutowireCandidate(PatternMatchUtils.simpleMatch(patterns, beanName)); } } else { bd.setAutowireCandidate(TRUE_VALUE.equals(autowireCandidate)); } // 解析 primary 属性 if (ele.hasAttribute(PRIMARY_ATTRIBUTE)) { bd.setPrimary(TRUE_VALUE.equals(ele.getAttribute(PRIMARY_ATTRIBUTE))); } // 解析 init-method 属性(这个方法,在初始化时会被调用~) if (ele.hasAttribute(INIT_METHOD_ATTRIBUTE)) { String initMethodName = ele.getAttribute(INIT_METHOD_ATTRIBUTE); bd.setInitMethodName(initMethodName); } // 如果用户没有设置初始化方法,而加载类有默认初始化方法,设置默认 else if (this.defaults.getInitMethod() != null) { bd.setInitMethodName(this.defaults.getInitMethod()); bd.setEnforceInitMethod(false); } // 解析 destroy-method 属性 if (ele.hasAttribute(DESTROY_METHOD_ATTRIBUTE)) { String destroyMethodName = ele.getAttribute(DESTROY_METHOD_ATTRIBUTE); bd.setDestroyMethodName(destroyMethodName); } else if (this.defaults.getDestroyMethod() != null) { bd.setDestroyMethodName(this.defaults.getDestroyMethod()); bd.setEnforceDestroyMethod(false); } // 解析 factory-method 属性 if (ele.hasAttribute(FACTORY_METHOD_ATTRIBUTE)) { bd.setFactoryMethodName(ele.getAttribute(FACTORY_METHOD_ATTRIBUTE)); } // 解析 factory-bean 属性 if (ele.hasAttribute(FACTORY_BEAN_ATTRIBUTE)) { bd.setFactoryBeanName(ele.getAttribute(FACTORY_BEAN_ATTRIBUTE)); } return bd; }
Example 2
Source File: GroovyBeanDefinitionWrapper.java From spring-analysis-note with MIT License | 4 votes |
@Override public void setProperty(String property, Object newValue) { if (PARENT.equals(property)) { setParent(newValue); } else { AbstractBeanDefinition bd = getBeanDefinition(); if (AUTOWIRE.equals(property)) { if ("byName".equals(newValue)) { bd.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_BY_NAME); } else if ("byType".equals(newValue)) { bd.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_BY_TYPE); } else if ("constructor".equals(newValue)) { bd.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_CONSTRUCTOR); } else if (Boolean.TRUE.equals(newValue)) { bd.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_BY_NAME); } } // constructorArgs else if (CONSTRUCTOR_ARGS.equals(property) && newValue instanceof List) { ConstructorArgumentValues cav = new ConstructorArgumentValues(); List args = (List) newValue; for (Object arg : args) { cav.addGenericArgumentValue(arg); } bd.setConstructorArgumentValues(cav); } // factoryBean else if (FACTORY_BEAN.equals(property)) { if (newValue != null) { bd.setFactoryBeanName(newValue.toString()); } } // factoryMethod else if (FACTORY_METHOD.equals(property)) { if (newValue != null) { bd.setFactoryMethodName(newValue.toString()); } } // initMethod else if (INIT_METHOD.equals(property)) { if (newValue != null) { bd.setInitMethodName(newValue.toString()); } } // destroyMethod else if (DESTROY_METHOD.equals(property)) { if (newValue != null) { bd.setDestroyMethodName(newValue.toString()); } } // singleton property else if (SINGLETON.equals(property)) { bd.setScope(Boolean.TRUE.equals(newValue) ? BeanDefinition.SCOPE_SINGLETON : BeanDefinition.SCOPE_PROTOTYPE); } else if (this.definitionWrapper.isWritableProperty(property)) { this.definitionWrapper.setPropertyValue(property, newValue); } else { super.setProperty(property, newValue); } } }
Example 3
Source File: BeanDefinitionParserDelegate.java From java-technology-stack with MIT License | 4 votes |
/** * Apply the attributes of the given bean element to the given bean * definition. * @param ele bean declaration element * @param beanName bean name * @param containingBean containing bean definition * @return a bean definition initialized according to the bean element attributes */ public AbstractBeanDefinition parseBeanDefinitionAttributes(Element ele, String beanName, @Nullable BeanDefinition containingBean, AbstractBeanDefinition bd) { if (ele.hasAttribute(SINGLETON_ATTRIBUTE)) { error("Old 1.x 'singleton' attribute in use - upgrade to 'scope' declaration", ele); } else if (ele.hasAttribute(SCOPE_ATTRIBUTE)) { bd.setScope(ele.getAttribute(SCOPE_ATTRIBUTE)); } else if (containingBean != null) { // Take default from containing bean in case of an inner bean definition. bd.setScope(containingBean.getScope()); } if (ele.hasAttribute(ABSTRACT_ATTRIBUTE)) { bd.setAbstract(TRUE_VALUE.equals(ele.getAttribute(ABSTRACT_ATTRIBUTE))); } String lazyInit = ele.getAttribute(LAZY_INIT_ATTRIBUTE); if (isDefaultValue(lazyInit)) { lazyInit = this.defaults.getLazyInit(); } bd.setLazyInit(TRUE_VALUE.equals(lazyInit)); String autowire = ele.getAttribute(AUTOWIRE_ATTRIBUTE); bd.setAutowireMode(getAutowireMode(autowire)); if (ele.hasAttribute(DEPENDS_ON_ATTRIBUTE)) { String dependsOn = ele.getAttribute(DEPENDS_ON_ATTRIBUTE); bd.setDependsOn(StringUtils.tokenizeToStringArray(dependsOn, MULTI_VALUE_ATTRIBUTE_DELIMITERS)); } String autowireCandidate = ele.getAttribute(AUTOWIRE_CANDIDATE_ATTRIBUTE); if (isDefaultValue(autowireCandidate)) { String candidatePattern = this.defaults.getAutowireCandidates(); if (candidatePattern != null) { String[] patterns = StringUtils.commaDelimitedListToStringArray(candidatePattern); bd.setAutowireCandidate(PatternMatchUtils.simpleMatch(patterns, beanName)); } } else { bd.setAutowireCandidate(TRUE_VALUE.equals(autowireCandidate)); } if (ele.hasAttribute(PRIMARY_ATTRIBUTE)) { bd.setPrimary(TRUE_VALUE.equals(ele.getAttribute(PRIMARY_ATTRIBUTE))); } if (ele.hasAttribute(INIT_METHOD_ATTRIBUTE)) { String initMethodName = ele.getAttribute(INIT_METHOD_ATTRIBUTE); bd.setInitMethodName(initMethodName); } else if (this.defaults.getInitMethod() != null) { bd.setInitMethodName(this.defaults.getInitMethod()); bd.setEnforceInitMethod(false); } if (ele.hasAttribute(DESTROY_METHOD_ATTRIBUTE)) { String destroyMethodName = ele.getAttribute(DESTROY_METHOD_ATTRIBUTE); bd.setDestroyMethodName(destroyMethodName); } else if (this.defaults.getDestroyMethod() != null) { bd.setDestroyMethodName(this.defaults.getDestroyMethod()); bd.setEnforceDestroyMethod(false); } if (ele.hasAttribute(FACTORY_METHOD_ATTRIBUTE)) { bd.setFactoryMethodName(ele.getAttribute(FACTORY_METHOD_ATTRIBUTE)); } if (ele.hasAttribute(FACTORY_BEAN_ATTRIBUTE)) { bd.setFactoryBeanName(ele.getAttribute(FACTORY_BEAN_ATTRIBUTE)); } return bd; }
Example 4
Source File: GroovyBeanDefinitionWrapper.java From java-technology-stack with MIT License | 4 votes |
@Override public void setProperty(String property, Object newValue) { if (PARENT.equals(property)) { setParent(newValue); } else { AbstractBeanDefinition bd = getBeanDefinition(); if (AUTOWIRE.equals(property)) { if ("byName".equals(newValue)) { bd.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_BY_NAME); } else if ("byType".equals(newValue)) { bd.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_BY_TYPE); } else if ("constructor".equals(newValue)) { bd.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_CONSTRUCTOR); } else if (Boolean.TRUE.equals(newValue)) { bd.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_BY_NAME); } } // constructorArgs else if (CONSTRUCTOR_ARGS.equals(property) && newValue instanceof List) { ConstructorArgumentValues cav = new ConstructorArgumentValues(); List args = (List) newValue; for (Object arg : args) { cav.addGenericArgumentValue(arg); } bd.setConstructorArgumentValues(cav); } // factoryBean else if (FACTORY_BEAN.equals(property)) { if (newValue != null) { bd.setFactoryBeanName(newValue.toString()); } } // factoryMethod else if (FACTORY_METHOD.equals(property)) { if (newValue != null) { bd.setFactoryMethodName(newValue.toString()); } } // initMethod else if (INIT_METHOD.equals(property)) { if (newValue != null) { bd.setInitMethodName(newValue.toString()); } } // destroyMethod else if (DESTROY_METHOD.equals(property)) { if (newValue != null) { bd.setDestroyMethodName(newValue.toString()); } } // singleton property else if (SINGLETON.equals(property)) { bd.setScope(Boolean.TRUE.equals(newValue) ? BeanDefinition.SCOPE_SINGLETON : BeanDefinition.SCOPE_PROTOTYPE); } else if (this.definitionWrapper.isWritableProperty(property)) { this.definitionWrapper.setPropertyValue(property, newValue); } else { super.setProperty(property, newValue); } } }
Example 5
Source File: BeanDefinitionParserDelegate.java From lams with GNU General Public License v2.0 | 4 votes |
/** * Apply the attributes of the given bean element to the given bean * definition. * @param ele bean declaration element * @param beanName bean name * @param containingBean containing bean definition * @return a bean definition initialized according to the bean element attributes */ public AbstractBeanDefinition parseBeanDefinitionAttributes(Element ele, String beanName, BeanDefinition containingBean, AbstractBeanDefinition bd) { if (ele.hasAttribute(SINGLETON_ATTRIBUTE)) { error("Old 1.x 'singleton' attribute in use - upgrade to 'scope' declaration", ele); } else if (ele.hasAttribute(SCOPE_ATTRIBUTE)) { bd.setScope(ele.getAttribute(SCOPE_ATTRIBUTE)); } else if (containingBean != null) { // Take default from containing bean in case of an inner bean definition. bd.setScope(containingBean.getScope()); } if (ele.hasAttribute(ABSTRACT_ATTRIBUTE)) { bd.setAbstract(TRUE_VALUE.equals(ele.getAttribute(ABSTRACT_ATTRIBUTE))); } String lazyInit = ele.getAttribute(LAZY_INIT_ATTRIBUTE); if (DEFAULT_VALUE.equals(lazyInit)) { lazyInit = this.defaults.getLazyInit(); } bd.setLazyInit(TRUE_VALUE.equals(lazyInit)); String autowire = ele.getAttribute(AUTOWIRE_ATTRIBUTE); bd.setAutowireMode(getAutowireMode(autowire)); String dependencyCheck = ele.getAttribute(DEPENDENCY_CHECK_ATTRIBUTE); bd.setDependencyCheck(getDependencyCheck(dependencyCheck)); if (ele.hasAttribute(DEPENDS_ON_ATTRIBUTE)) { String dependsOn = ele.getAttribute(DEPENDS_ON_ATTRIBUTE); bd.setDependsOn(StringUtils.tokenizeToStringArray(dependsOn, MULTI_VALUE_ATTRIBUTE_DELIMITERS)); } String autowireCandidate = ele.getAttribute(AUTOWIRE_CANDIDATE_ATTRIBUTE); if ("".equals(autowireCandidate) || DEFAULT_VALUE.equals(autowireCandidate)) { String candidatePattern = this.defaults.getAutowireCandidates(); if (candidatePattern != null) { String[] patterns = StringUtils.commaDelimitedListToStringArray(candidatePattern); bd.setAutowireCandidate(PatternMatchUtils.simpleMatch(patterns, beanName)); } } else { bd.setAutowireCandidate(TRUE_VALUE.equals(autowireCandidate)); } if (ele.hasAttribute(PRIMARY_ATTRIBUTE)) { bd.setPrimary(TRUE_VALUE.equals(ele.getAttribute(PRIMARY_ATTRIBUTE))); } if (ele.hasAttribute(INIT_METHOD_ATTRIBUTE)) { String initMethodName = ele.getAttribute(INIT_METHOD_ATTRIBUTE); if (!"".equals(initMethodName)) { bd.setInitMethodName(initMethodName); } } else { if (this.defaults.getInitMethod() != null) { bd.setInitMethodName(this.defaults.getInitMethod()); bd.setEnforceInitMethod(false); } } if (ele.hasAttribute(DESTROY_METHOD_ATTRIBUTE)) { String destroyMethodName = ele.getAttribute(DESTROY_METHOD_ATTRIBUTE); bd.setDestroyMethodName(destroyMethodName); } else { if (this.defaults.getDestroyMethod() != null) { bd.setDestroyMethodName(this.defaults.getDestroyMethod()); bd.setEnforceDestroyMethod(false); } } if (ele.hasAttribute(FACTORY_METHOD_ATTRIBUTE)) { bd.setFactoryMethodName(ele.getAttribute(FACTORY_METHOD_ATTRIBUTE)); } if (ele.hasAttribute(FACTORY_BEAN_ATTRIBUTE)) { bd.setFactoryBeanName(ele.getAttribute(FACTORY_BEAN_ATTRIBUTE)); } return bd; }
Example 6
Source File: GroovyBeanDefinitionWrapper.java From lams with GNU General Public License v2.0 | 4 votes |
public void setProperty(String property, Object newValue) { if (PARENT.equals(property)) { setParent(newValue); } else { AbstractBeanDefinition bd = getBeanDefinition(); if (AUTOWIRE.equals(property)) { if ("byName".equals(newValue)) { bd.setAutowireMode(AutowireCapableBeanFactory.AUTOWIRE_BY_NAME); } else if ("byType".equals(newValue)) { bd.setAutowireMode(AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE); } else if ("constructor".equals(newValue)) { bd.setAutowireMode(AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR); } else if (Boolean.TRUE.equals(newValue)) { bd.setAutowireMode(AutowireCapableBeanFactory.AUTOWIRE_BY_NAME); } } // constructorArgs else if (CONSTRUCTOR_ARGS.equals(property) && newValue instanceof List) { ConstructorArgumentValues cav = new ConstructorArgumentValues(); List args = (List) newValue; for (Object arg : args) { cav.addGenericArgumentValue(arg); } bd.setConstructorArgumentValues(cav); } // factoryBean else if (FACTORY_BEAN.equals(property)) { if (newValue != null) { bd.setFactoryBeanName(newValue.toString()); } } // factoryMethod else if (FACTORY_METHOD.equals(property)) { if (newValue != null) bd.setFactoryMethodName(newValue.toString()); } // initMethod else if (INIT_METHOD.equals(property)) { if (newValue != null) { bd.setInitMethodName(newValue.toString()); } } // destroyMethod else if (DESTROY_METHOD.equals(property)) { if (newValue != null) { bd.setDestroyMethodName(newValue.toString()); } } // singleton property else if (SINGLETON.equals(property)) { bd.setScope(Boolean.TRUE.equals(newValue) ? BeanDefinition.SCOPE_SINGLETON : BeanDefinition.SCOPE_PROTOTYPE); } else if (this.definitionWrapper.isWritableProperty(property)) { this.definitionWrapper.setPropertyValue(property, newValue); } else { super.setProperty(property, newValue); } } }
Example 7
Source File: BeanDefinitionParserDelegate.java From blog_demos with Apache License 2.0 | 4 votes |
/** * Apply the attributes of the given bean element to the given bean * definition. * @param ele bean declaration element * @param beanName bean name * @param containingBean containing bean definition * @return a bean definition initialized according to the bean element attributes */ public AbstractBeanDefinition parseBeanDefinitionAttributes(Element ele, String beanName, BeanDefinition containingBean, AbstractBeanDefinition bd) { if (ele.hasAttribute(SCOPE_ATTRIBUTE)) { bd.setScope(ele.getAttribute(SCOPE_ATTRIBUTE)); } else if (containingBean != null) { // Take default from containing bean in case of an inner bean definition. bd.setScope(containingBean.getScope()); } if (ele.hasAttribute(ABSTRACT_ATTRIBUTE)) { bd.setAbstract(TRUE_VALUE.equals(ele.getAttribute(ABSTRACT_ATTRIBUTE))); } String lazyInit = ele.getAttribute(LAZY_INIT_ATTRIBUTE); if (DEFAULT_VALUE.equals(lazyInit)) { lazyInit = this.defaults.getLazyInit(); } bd.setLazyInit(TRUE_VALUE.equals(lazyInit)); String autowire = ele.getAttribute(AUTOWIRE_ATTRIBUTE); bd.setAutowireMode(getAutowireMode(autowire)); String dependencyCheck = ele.getAttribute(DEPENDENCY_CHECK_ATTRIBUTE); bd.setDependencyCheck(getDependencyCheck(dependencyCheck)); if (ele.hasAttribute(DEPENDS_ON_ATTRIBUTE)) { String dependsOn = ele.getAttribute(DEPENDS_ON_ATTRIBUTE); bd.setDependsOn(StringUtils.tokenizeToStringArray(dependsOn, MULTI_VALUE_ATTRIBUTE_DELIMITERS)); } String autowireCandidate = ele.getAttribute(AUTOWIRE_CANDIDATE_ATTRIBUTE); if ("".equals(autowireCandidate) || DEFAULT_VALUE.equals(autowireCandidate)) { String candidatePattern = this.defaults.getAutowireCandidates(); if (candidatePattern != null) { String[] patterns = StringUtils.commaDelimitedListToStringArray(candidatePattern); bd.setAutowireCandidate(PatternMatchUtils.simpleMatch(patterns, beanName)); } } else { bd.setAutowireCandidate(TRUE_VALUE.equals(autowireCandidate)); } if (ele.hasAttribute(PRIMARY_ATTRIBUTE)) { bd.setPrimary(TRUE_VALUE.equals(ele.getAttribute(PRIMARY_ATTRIBUTE))); } if (ele.hasAttribute(INIT_METHOD_ATTRIBUTE)) { String initMethodName = ele.getAttribute(INIT_METHOD_ATTRIBUTE); if (!"".equals(initMethodName)) { bd.setInitMethodName(initMethodName); } } else { if (this.defaults.getInitMethod() != null) { bd.setInitMethodName(this.defaults.getInitMethod()); bd.setEnforceInitMethod(false); } } if (ele.hasAttribute(DESTROY_METHOD_ATTRIBUTE)) { String destroyMethodName = ele.getAttribute(DESTROY_METHOD_ATTRIBUTE); if (!"".equals(destroyMethodName)) { bd.setDestroyMethodName(destroyMethodName); } } else { if (this.defaults.getDestroyMethod() != null) { bd.setDestroyMethodName(this.defaults.getDestroyMethod()); bd.setEnforceDestroyMethod(false); } } if (ele.hasAttribute(FACTORY_METHOD_ATTRIBUTE)) { bd.setFactoryMethodName(ele.getAttribute(FACTORY_METHOD_ATTRIBUTE)); } if (ele.hasAttribute(FACTORY_BEAN_ATTRIBUTE)) { bd.setFactoryBeanName(ele.getAttribute(FACTORY_BEAN_ATTRIBUTE)); } return bd; }
Example 8
Source File: GroovyBeanDefinitionWrapper.java From blog_demos with Apache License 2.0 | 4 votes |
public void setProperty(String property, Object newValue) { if (PARENT.equals(property)) { setParent(newValue); } else { AbstractBeanDefinition bd = getBeanDefinition(); if (AUTOWIRE.equals(property)) { if ("byName".equals(newValue)) { bd.setAutowireMode(AutowireCapableBeanFactory.AUTOWIRE_BY_NAME); } else if ("byType".equals(newValue)) { bd.setAutowireMode(AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE); } else if ("constructor".equals(newValue)) { bd.setAutowireMode(AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR); } else if (Boolean.TRUE.equals(newValue)) { bd.setAutowireMode(AutowireCapableBeanFactory.AUTOWIRE_BY_NAME); } } // constructorArgs else if (CONSTRUCTOR_ARGS.equals(property) && newValue instanceof List) { ConstructorArgumentValues cav = new ConstructorArgumentValues(); List args = (List) newValue; for (Object arg : args) { cav.addGenericArgumentValue(arg); } bd.setConstructorArgumentValues(cav); } // factoryBean else if (FACTORY_BEAN.equals(property)) { if (newValue != null) { bd.setFactoryBeanName(newValue.toString()); } } // factoryMethod else if (FACTORY_METHOD.equals(property)) { if (newValue != null) bd.setFactoryMethodName(newValue.toString()); } // initMethod else if (INIT_METHOD.equals(property)) { if (newValue != null) { bd.setInitMethodName(newValue.toString()); } } // destroyMethod else if (DESTROY_METHOD.equals(property)) { if (newValue != null) { bd.setDestroyMethodName(newValue.toString()); } } // singleton property else if (SINGLETON.equals(property)) { bd.setScope(Boolean.TRUE.equals(newValue) ? BeanDefinition.SCOPE_SINGLETON : BeanDefinition.SCOPE_PROTOTYPE); } else if (this.definitionWrapper.isWritableProperty(property)) { this.definitionWrapper.setPropertyValue(property, newValue); } else { super.setProperty(property, newValue); } } }
Example 9
Source File: GroovyBeanDefinitionWrapper.java From spring4-understanding with Apache License 2.0 | 4 votes |
public void setProperty(String property, Object newValue) { if (PARENT.equals(property)) { setParent(newValue); } else { AbstractBeanDefinition bd = getBeanDefinition(); if (AUTOWIRE.equals(property)) { if ("byName".equals(newValue)) { bd.setAutowireMode(AutowireCapableBeanFactory.AUTOWIRE_BY_NAME); } else if ("byType".equals(newValue)) { bd.setAutowireMode(AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE); } else if ("constructor".equals(newValue)) { bd.setAutowireMode(AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR); } else if (Boolean.TRUE.equals(newValue)) { bd.setAutowireMode(AutowireCapableBeanFactory.AUTOWIRE_BY_NAME); } } // constructorArgs else if (CONSTRUCTOR_ARGS.equals(property) && newValue instanceof List) { ConstructorArgumentValues cav = new ConstructorArgumentValues(); List args = (List) newValue; for (Object arg : args) { cav.addGenericArgumentValue(arg); } bd.setConstructorArgumentValues(cav); } // factoryBean else if (FACTORY_BEAN.equals(property)) { if (newValue != null) { bd.setFactoryBeanName(newValue.toString()); } } // factoryMethod else if (FACTORY_METHOD.equals(property)) { if (newValue != null) bd.setFactoryMethodName(newValue.toString()); } // initMethod else if (INIT_METHOD.equals(property)) { if (newValue != null) { bd.setInitMethodName(newValue.toString()); } } // destroyMethod else if (DESTROY_METHOD.equals(property)) { if (newValue != null) { bd.setDestroyMethodName(newValue.toString()); } } // singleton property else if (SINGLETON.equals(property)) { bd.setScope(Boolean.TRUE.equals(newValue) ? BeanDefinition.SCOPE_SINGLETON : BeanDefinition.SCOPE_PROTOTYPE); } else if (this.definitionWrapper.isWritableProperty(property)) { this.definitionWrapper.setPropertyValue(property, newValue); } else { super.setProperty(property, newValue); } } }
Example 10
Source File: BeanDefinitionParserDelegate.java From spring4-understanding with Apache License 2.0 | 4 votes |
/** * Apply the attributes of the given bean element to the given bean * definition. * @param ele bean declaration element * @param beanName bean name * @param containingBean containing bean definition * @return a bean definition initialized according to the bean element attributes */ public AbstractBeanDefinition parseBeanDefinitionAttributes(Element ele, String beanName, BeanDefinition containingBean, AbstractBeanDefinition bd) { if (ele.hasAttribute(SINGLETON_ATTRIBUTE)) { error("Old 1.x 'singleton' attribute in use - upgrade to 'scope' declaration", ele); } else if (ele.hasAttribute(SCOPE_ATTRIBUTE)) { bd.setScope(ele.getAttribute(SCOPE_ATTRIBUTE)); } else if (containingBean != null) { // Take default from containing bean in case of an inner bean definition. bd.setScope(containingBean.getScope()); } if (ele.hasAttribute(ABSTRACT_ATTRIBUTE)) { bd.setAbstract(TRUE_VALUE.equals(ele.getAttribute(ABSTRACT_ATTRIBUTE))); } String lazyInit = ele.getAttribute(LAZY_INIT_ATTRIBUTE); if (DEFAULT_VALUE.equals(lazyInit)) { lazyInit = this.defaults.getLazyInit(); } bd.setLazyInit(TRUE_VALUE.equals(lazyInit)); String autowire = ele.getAttribute(AUTOWIRE_ATTRIBUTE); bd.setAutowireMode(getAutowireMode(autowire)); String dependencyCheck = ele.getAttribute(DEPENDENCY_CHECK_ATTRIBUTE); bd.setDependencyCheck(getDependencyCheck(dependencyCheck)); if (ele.hasAttribute(DEPENDS_ON_ATTRIBUTE)) { String dependsOn = ele.getAttribute(DEPENDS_ON_ATTRIBUTE); bd.setDependsOn(StringUtils.tokenizeToStringArray(dependsOn, MULTI_VALUE_ATTRIBUTE_DELIMITERS)); } String autowireCandidate = ele.getAttribute(AUTOWIRE_CANDIDATE_ATTRIBUTE); if ("".equals(autowireCandidate) || DEFAULT_VALUE.equals(autowireCandidate)) { String candidatePattern = this.defaults.getAutowireCandidates(); if (candidatePattern != null) { String[] patterns = StringUtils.commaDelimitedListToStringArray(candidatePattern); bd.setAutowireCandidate(PatternMatchUtils.simpleMatch(patterns, beanName)); } } else { bd.setAutowireCandidate(TRUE_VALUE.equals(autowireCandidate)); } if (ele.hasAttribute(PRIMARY_ATTRIBUTE)) { bd.setPrimary(TRUE_VALUE.equals(ele.getAttribute(PRIMARY_ATTRIBUTE))); } if (ele.hasAttribute(INIT_METHOD_ATTRIBUTE)) { String initMethodName = ele.getAttribute(INIT_METHOD_ATTRIBUTE); if (!"".equals(initMethodName)) { bd.setInitMethodName(initMethodName); } } else { if (this.defaults.getInitMethod() != null) { bd.setInitMethodName(this.defaults.getInitMethod()); bd.setEnforceInitMethod(false); } } if (ele.hasAttribute(DESTROY_METHOD_ATTRIBUTE)) { String destroyMethodName = ele.getAttribute(DESTROY_METHOD_ATTRIBUTE); bd.setDestroyMethodName(destroyMethodName); } else { if (this.defaults.getDestroyMethod() != null) { bd.setDestroyMethodName(this.defaults.getDestroyMethod()); bd.setEnforceDestroyMethod(false); } } if (ele.hasAttribute(FACTORY_METHOD_ATTRIBUTE)) { bd.setFactoryMethodName(ele.getAttribute(FACTORY_METHOD_ATTRIBUTE)); } if (ele.hasAttribute(FACTORY_BEAN_ATTRIBUTE)) { bd.setFactoryBeanName(ele.getAttribute(FACTORY_BEAN_ATTRIBUTE)); } return bd; }