|
|
|
@ -17,10 +17,10 @@ |
|
|
|
package org.springframework.aop.aspectj.annotation; |
|
|
|
package org.springframework.aop.aspectj.annotation; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.Collections; |
|
|
|
import java.util.Collections; |
|
|
|
import java.util.HashMap; |
|
|
|
|
|
|
|
import java.util.LinkedList; |
|
|
|
import java.util.LinkedList; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
import java.util.concurrent.ConcurrentHashMap; |
|
|
|
|
|
|
|
|
|
|
|
import org.aspectj.lang.reflect.PerClauseKind; |
|
|
|
import org.aspectj.lang.reflect.PerClauseKind; |
|
|
|
|
|
|
|
|
|
|
|
@ -43,12 +43,11 @@ public class BeanFactoryAspectJAdvisorsBuilder { |
|
|
|
|
|
|
|
|
|
|
|
private final AspectJAdvisorFactory advisorFactory; |
|
|
|
private final AspectJAdvisorFactory advisorFactory; |
|
|
|
|
|
|
|
|
|
|
|
private List<String> aspectBeanNames; |
|
|
|
private volatile List<String> aspectBeanNames; |
|
|
|
|
|
|
|
|
|
|
|
private final Map<String, List<Advisor>> advisorsCache = new HashMap<>(); |
|
|
|
private final Map<String, List<Advisor>> advisorsCache = new ConcurrentHashMap<>(); |
|
|
|
|
|
|
|
|
|
|
|
private final Map<String, MetadataAwareAspectInstanceFactory> aspectFactoryCache = |
|
|
|
private final Map<String, MetadataAwareAspectInstanceFactory> aspectFactoryCache = new ConcurrentHashMap<>(); |
|
|
|
new HashMap<>(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
@ -56,7 +55,7 @@ public class BeanFactoryAspectJAdvisorsBuilder { |
|
|
|
* @param beanFactory the ListableBeanFactory to scan |
|
|
|
* @param beanFactory the ListableBeanFactory to scan |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public BeanFactoryAspectJAdvisorsBuilder(ListableBeanFactory beanFactory) { |
|
|
|
public BeanFactoryAspectJAdvisorsBuilder(ListableBeanFactory beanFactory) { |
|
|
|
this(beanFactory, new ReflectiveAspectJAdvisorFactory()); |
|
|
|
this(beanFactory, new ReflectiveAspectJAdvisorFactory(beanFactory)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
@ -80,22 +79,22 @@ public class BeanFactoryAspectJAdvisorsBuilder { |
|
|
|
* @see #isEligibleBean |
|
|
|
* @see #isEligibleBean |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public List<Advisor> buildAspectJAdvisors() { |
|
|
|
public List<Advisor> buildAspectJAdvisors() { |
|
|
|
List<String> aspectNames = null; |
|
|
|
List<String> aspectNames = this.aspectBeanNames; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (aspectNames == null) { |
|
|
|
synchronized (this) { |
|
|
|
synchronized (this) { |
|
|
|
aspectNames = this.aspectBeanNames; |
|
|
|
aspectNames = this.aspectBeanNames; |
|
|
|
if (aspectNames == null) { |
|
|
|
if (aspectNames == null) { |
|
|
|
List<Advisor> advisors = new LinkedList<>(); |
|
|
|
List<Advisor> advisors = new LinkedList<>(); |
|
|
|
aspectNames = new LinkedList<>(); |
|
|
|
aspectNames = new LinkedList<>(); |
|
|
|
String[] beanNames = |
|
|
|
String[] beanNames = BeanFactoryUtils.beanNamesForTypeIncludingAncestors( |
|
|
|
BeanFactoryUtils.beanNamesForTypeIncludingAncestors(this.beanFactory, Object.class, true, false); |
|
|
|
this.beanFactory, Object.class, true, false); |
|
|
|
for (String beanName : beanNames) { |
|
|
|
for (String beanName : beanNames) { |
|
|
|
if (!isEligibleBean(beanName)) { |
|
|
|
if (!isEligibleBean(beanName)) { |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
// We must be careful not to instantiate beans eagerly as in this
|
|
|
|
// We must be careful not to instantiate beans eagerly as in this case they
|
|
|
|
// case they would be cached by the Spring container but would not
|
|
|
|
// would be cached by the Spring container but would not have been weaved.
|
|
|
|
// have been weaved
|
|
|
|
|
|
|
|
Class<?> beanType = this.beanFactory.getType(beanName); |
|
|
|
Class<?> beanType = this.beanFactory.getType(beanName); |
|
|
|
if (beanType == null) { |
|
|
|
if (beanType == null) { |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
@ -132,6 +131,7 @@ public class BeanFactoryAspectJAdvisorsBuilder { |
|
|
|
return advisors; |
|
|
|
return advisors; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (aspectNames.isEmpty()) { |
|
|
|
if (aspectNames.isEmpty()) { |
|
|
|
return Collections.emptyList(); |
|
|
|
return Collections.emptyList(); |
|
|
|
|