From ab9d947c08c5a5984e28691a0e951207460af1f2 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Thu, 24 Jul 2014 17:46:04 +0200 Subject: [PATCH] DefaultListableBeanFactory's registerBeanDefinition only calls resetBeanDefinition in case of pre-existing bean definition or pre-existing singleton instance Issue: SPR-8318 (cherry picked from commit a4968b9) --- .../factory/support/DefaultListableBeanFactory.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java index 1dfc49cc8c..7a874cce93 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java @@ -657,8 +657,10 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto } } + BeanDefinition oldBeanDefinition; + synchronized (this.beanDefinitionMap) { - Object oldBeanDefinition = this.beanDefinitionMap.get(beanName); + oldBeanDefinition = this.beanDefinitionMap.get(beanName); if (oldBeanDefinition != null) { if (!this.allowBeanDefinitionOverriding) { throw new BeanDefinitionStoreException(beanDefinition.getResourceDescription(), beanName, @@ -679,7 +681,9 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto this.beanDefinitionMap.put(beanName, beanDefinition); } - resetBeanDefinition(beanName); + if (oldBeanDefinition != null || containsSingleton(beanName)) { + resetBeanDefinition(beanName); + } } public void removeBeanDefinition(String beanName) throws NoSuchBeanDefinitionException { @@ -714,9 +718,6 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto // (e.g. the default StaticMessageSource in a StaticApplicationContext). destroySingleton(beanName); - // Remove any assumptions about by-type mappings. - clearByTypeCache(); - // Reset all bean definitions that have the given bean as parent (recursively). for (String bdName : this.beanDefinitionNames) { if (!beanName.equals(bdName)) {