|
|
|
@ -1,5 +1,5 @@ |
|
|
|
/* |
|
|
|
/* |
|
|
|
* Copyright 2002-2020 the original author or authors. |
|
|
|
* Copyright 2002-2024 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. |
|
|
|
@ -22,9 +22,12 @@ import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.concurrent.ConcurrentHashMap; |
|
|
|
import java.util.concurrent.ConcurrentHashMap; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.apache.commons.logging.Log; |
|
|
|
|
|
|
|
import org.apache.commons.logging.LogFactory; |
|
|
|
import org.aspectj.lang.reflect.PerClauseKind; |
|
|
|
import org.aspectj.lang.reflect.PerClauseKind; |
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.aop.Advisor; |
|
|
|
import org.springframework.aop.Advisor; |
|
|
|
|
|
|
|
import org.springframework.aop.framework.AopConfigException; |
|
|
|
import org.springframework.beans.factory.BeanFactoryUtils; |
|
|
|
import org.springframework.beans.factory.BeanFactoryUtils; |
|
|
|
import org.springframework.beans.factory.ListableBeanFactory; |
|
|
|
import org.springframework.beans.factory.ListableBeanFactory; |
|
|
|
import org.springframework.lang.Nullable; |
|
|
|
import org.springframework.lang.Nullable; |
|
|
|
@ -40,6 +43,8 @@ import org.springframework.util.Assert; |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class BeanFactoryAspectJAdvisorsBuilder { |
|
|
|
public class BeanFactoryAspectJAdvisorsBuilder { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static final Log logger = LogFactory.getLog(BeanFactoryAspectJAdvisorsBuilder.class); |
|
|
|
|
|
|
|
|
|
|
|
private final ListableBeanFactory beanFactory; |
|
|
|
private final ListableBeanFactory beanFactory; |
|
|
|
|
|
|
|
|
|
|
|
private final AspectJAdvisorFactory advisorFactory; |
|
|
|
private final AspectJAdvisorFactory advisorFactory; |
|
|
|
@ -102,30 +107,37 @@ public class BeanFactoryAspectJAdvisorsBuilder { |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
if (this.advisorFactory.isAspect(beanType)) { |
|
|
|
if (this.advisorFactory.isAspect(beanType)) { |
|
|
|
aspectNames.add(beanName); |
|
|
|
try { |
|
|
|
AspectMetadata amd = new AspectMetadata(beanType, beanName); |
|
|
|
AspectMetadata amd = new AspectMetadata(beanType, beanName); |
|
|
|
if (amd.getAjType().getPerClause().getKind() == PerClauseKind.SINGLETON) { |
|
|
|
if (amd.getAjType().getPerClause().getKind() == PerClauseKind.SINGLETON) { |
|
|
|
MetadataAwareAspectInstanceFactory factory = |
|
|
|
MetadataAwareAspectInstanceFactory factory = |
|
|
|
new BeanFactoryAspectInstanceFactory(this.beanFactory, beanName); |
|
|
|
new BeanFactoryAspectInstanceFactory(this.beanFactory, beanName); |
|
|
|
List<Advisor> classAdvisors = this.advisorFactory.getAdvisors(factory); |
|
|
|
List<Advisor> classAdvisors = this.advisorFactory.getAdvisors(factory); |
|
|
|
if (this.beanFactory.isSingleton(beanName)) { |
|
|
|
if (this.beanFactory.isSingleton(beanName)) { |
|
|
|
this.advisorsCache.put(beanName, classAdvisors); |
|
|
|
this.advisorsCache.put(beanName, classAdvisors); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else { |
|
|
|
|
|
|
|
this.aspectFactoryCache.put(beanName, factory); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
advisors.addAll(classAdvisors); |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
else { |
|
|
|
|
|
|
|
// Per target or per this.
|
|
|
|
|
|
|
|
if (this.beanFactory.isSingleton(beanName)) { |
|
|
|
|
|
|
|
throw new IllegalArgumentException("Bean with name '" + beanName + |
|
|
|
|
|
|
|
"' is a singleton, but aspect instantiation model is not singleton"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
MetadataAwareAspectInstanceFactory factory = |
|
|
|
|
|
|
|
new PrototypeAspectInstanceFactory(this.beanFactory, beanName); |
|
|
|
this.aspectFactoryCache.put(beanName, factory); |
|
|
|
this.aspectFactoryCache.put(beanName, factory); |
|
|
|
|
|
|
|
advisors.addAll(this.advisorFactory.getAdvisors(factory)); |
|
|
|
} |
|
|
|
} |
|
|
|
advisors.addAll(classAdvisors); |
|
|
|
aspectNames.add(beanName); |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
catch (IllegalArgumentException | IllegalStateException | AopConfigException ex) { |
|
|
|
// Per target or per this.
|
|
|
|
if (logger.isDebugEnabled()) { |
|
|
|
if (this.beanFactory.isSingleton(beanName)) { |
|
|
|
logger.debug("Ignoring incompatible aspect [" + beanType.getName() + "]: " + ex); |
|
|
|
throw new IllegalArgumentException("Bean with name '" + beanName + |
|
|
|
|
|
|
|
"' is a singleton, but aspect instantiation model is not singleton"); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
MetadataAwareAspectInstanceFactory factory = |
|
|
|
|
|
|
|
new PrototypeAspectInstanceFactory(this.beanFactory, beanName); |
|
|
|
|
|
|
|
this.aspectFactoryCache.put(beanName, factory); |
|
|
|
|
|
|
|
advisors.addAll(this.advisorFactory.getAdvisors(factory)); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|