1 16 17 package org.springframework.aop.framework.autoproxy; 18 19 import java.util.LinkedList ; 20 import java.util.List ; 21 22 import org.apache.commons.logging.Log; 23 import org.apache.commons.logging.LogFactory; 24 25 import org.springframework.aop.Advisor; 26 import org.springframework.beans.factory.BeanCreationException; 27 import org.springframework.beans.factory.BeanCurrentlyInCreationException; 28 import org.springframework.beans.factory.BeanFactoryUtils; 29 import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; 30 import org.springframework.util.Assert; 31 32 40 public class BeanFactoryAdvisorRetrievalHelper { 41 42 private static final Log logger = LogFactory.getLog(BeanFactoryAdvisorRetrievalHelper.class); 43 44 private final ConfigurableListableBeanFactory beanFactory; 45 46 47 51 public BeanFactoryAdvisorRetrievalHelper(ConfigurableListableBeanFactory beanFactory) { 52 Assert.notNull(beanFactory, "ListableBeanFactory must not be null"); 53 this.beanFactory = beanFactory; 54 } 55 56 57 63 public List findAdvisorBeans() { 64 List advisors = new LinkedList (); 65 String [] advisorNames = 68 BeanFactoryUtils.beanNamesForTypeIncludingAncestors(this.beanFactory, Advisor.class, true, false); 69 for (int i = 0; i < advisorNames.length; i++) { 70 String name = advisorNames[i]; 71 if (isEligibleBean(name) && !this.beanFactory.isCurrentlyInCreation(name)) { 72 try { 73 advisors.add(this.beanFactory.getBean(name)); 74 } 75 catch (BeanCreationException ex) { 76 Throwable rootCause = ex.getMostSpecificCause(); 77 if (rootCause instanceof BeanCurrentlyInCreationException) { 78 BeanCreationException bce = (BeanCreationException) rootCause; 79 if (this.beanFactory.isCurrentlyInCreation(bce.getBeanName())) { 80 if (logger.isDebugEnabled()) { 81 logger.debug("Ignoring currently created advisor '" + name + "': " + ex.getMessage()); 82 } 83 continue; 86 } 87 } 88 throw ex; 89 } 90 } 91 } 92 return advisors; 93 } 94 95 101 protected boolean isEligibleBean(String beanName) { 102 return true; 103 } 104 105 } 106 | Popular Tags |