diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/BeanFactoryAdvisorRetrievalHelper.java b/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/BeanFactoryAdvisorRetrievalHelper.java index e18aac6153..4e912f472e 100644 --- a/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/BeanFactoryAdvisorRetrievalHelper.java +++ b/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/BeanFactoryAdvisorRetrievalHelper.java @@ -45,7 +45,7 @@ public class BeanFactoryAdvisorRetrievalHelper { private final ConfigurableListableBeanFactory beanFactory; @Nullable - private String[] cachedAdvisorBeanNames; + private volatile String[] cachedAdvisorBeanNames; /** @@ -66,16 +66,13 @@ public class BeanFactoryAdvisorRetrievalHelper { */ public List findAdvisorBeans() { // Determine list of advisor bean names, if not cached already. - String[] advisorNames = null; - synchronized (this) { - advisorNames = this.cachedAdvisorBeanNames; - if (advisorNames == null) { - // Do not initialize FactoryBeans here: We need to leave all regular beans - // uninitialized to let the auto-proxy creator apply to them! - advisorNames = BeanFactoryUtils.beanNamesForTypeIncludingAncestors( - this.beanFactory, Advisor.class, true, false); - this.cachedAdvisorBeanNames = advisorNames; - } + String[] advisorNames = this.cachedAdvisorBeanNames; + if (advisorNames == null) { + // Do not initialize FactoryBeans here: We need to leave all regular beans + // uninitialized to let the auto-proxy creator apply to them! + advisorNames = BeanFactoryUtils.beanNamesForTypeIncludingAncestors( + this.beanFactory, Advisor.class, true, false); + this.cachedAdvisorBeanNames = advisorNames; } if (advisorNames.length == 0) { return new ArrayList<>();