Refined logging for advisors which are currently in creation

Issue: SPR-10430
This commit is contained in:
Juergen Hoeller 2013-10-30 00:29:21 +01:00
parent 7ca09d7e3d
commit 62157fe38f
1 changed files with 26 additions and 18 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2012 the original author or authors. * Copyright 2002-2013 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -81,24 +81,32 @@ public class BeanFactoryAdvisorRetrievalHelper {
List<Advisor> advisors = new LinkedList<Advisor>(); List<Advisor> advisors = new LinkedList<Advisor>();
for (String name : advisorNames) { for (String name : advisorNames) {
if (isEligibleBean(name) && !this.beanFactory.isCurrentlyInCreation(name)) { if (isEligibleBean(name)) {
try { if (this.beanFactory.isCurrentlyInCreation(name)) {
advisors.add(this.beanFactory.getBean(name, Advisor.class)); if (logger.isDebugEnabled()) {
} logger.debug("Skipping currently created advisor '" + name + "'");
catch (BeanCreationException ex) { }
Throwable rootCause = ex.getMostSpecificCause(); }
if (rootCause instanceof BeanCurrentlyInCreationException) { else {
BeanCreationException bce = (BeanCreationException) rootCause; try {
if (this.beanFactory.isCurrentlyInCreation(bce.getBeanName())) { advisors.add(this.beanFactory.getBean(name, Advisor.class));
if (logger.isDebugEnabled()) { }
logger.debug("Ignoring currently created advisor '" + name + "': " + ex.getMessage()); catch (BeanCreationException ex) {
} Throwable rootCause = ex.getMostSpecificCause();
// Ignore: indicates a reference back to the bean we're trying to advise. if (rootCause instanceof BeanCurrentlyInCreationException) {
// We want to find advisors other than the currently created bean itself. BeanCreationException bce = (BeanCreationException) rootCause;
continue; if (this.beanFactory.isCurrentlyInCreation(bce.getBeanName())) {
} if (logger.isDebugEnabled()) {
logger.debug("Skipping advisor '" + name +
"' with dependency on currently created bean: " + ex.getMessage());
}
// Ignore: indicates a reference back to the bean we're trying to advise.
// We want to find advisors other than the currently created bean itself.
continue;
}
}
throw ex;
} }
throw ex;
} }
} }
} }