1818
1919import java .lang .annotation .Annotation ;
2020import java .lang .reflect .Constructor ;
21+ import java .lang .reflect .Field ;
2122import java .lang .reflect .Method ;
2223import java .util .Map ;
2324import java .util .StringTokenizer ;
3738
3839import org .springframework .aop .framework .AopConfigException ;
3940import org .springframework .core .ParameterNameDiscoverer ;
41+ import org .springframework .core .SpringProperties ;
4042import org .springframework .core .annotation .AnnotationUtils ;
4143import org .springframework .lang .Nullable ;
4244
@@ -58,6 +60,23 @@ public abstract class AbstractAspectJAdvisorFactory implements AspectJAdvisorFac
5860 private static final Class <?>[] ASPECTJ_ANNOTATION_CLASSES = new Class <?>[] {
5961 Pointcut .class , Around .class , Before .class , After .class , AfterReturning .class , AfterThrowing .class };
6062
63+ private static final String AJC_MAGIC = "ajc$" ;
64+
65+ /**
66+ * System property that instructs Spring to ignore ajc-compiled aspects
67+ * for Spring AOP proxying, restoring traditional Spring behavior for
68+ * scenarios where both weaving and AspectJ auto-proxying are enabled.
69+ * <p>The default is "false". Consider switching this to "true" if you
70+ * encounter double execution of your aspects in a given build setup.
71+ * Note that we recommend restructuring your AspectJ configuration to
72+ * avoid such double exposure of an AspectJ aspect to begin with.
73+ * @since 6.1.15
74+ */
75+ public static final String IGNORE_AJC_PROPERTY_NAME = "spring.aop.ajc.ignore" ;
76+
77+ private static final boolean shouldIgnoreAjcCompiledAspects =
78+ SpringProperties .getFlag (IGNORE_AJC_PROPERTY_NAME );
79+
6180
6281 /** Logger available to subclasses. */
6382 protected final Log logger = LogFactory .getLog (getClass ());
@@ -67,7 +86,8 @@ public abstract class AbstractAspectJAdvisorFactory implements AspectJAdvisorFac
6786
6887 @ Override
6988 public boolean isAspect (Class <?> clazz ) {
70- return (AnnotationUtils .findAnnotation (clazz , Aspect .class ) != null );
89+ return (AnnotationUtils .findAnnotation (clazz , Aspect .class ) != null &&
90+ (!shouldIgnoreAjcCompiledAspects || !compiledByAjc (clazz )));
7191 }
7292
7393 @ Override
@@ -114,6 +134,16 @@ private static AspectJAnnotation findAnnotation(Method method, Class<? extends A
114134 }
115135 }
116136
137+ private static boolean compiledByAjc (Class <?> clazz ) {
138+ for (Field field : clazz .getDeclaredFields ()) {
139+ System .out .println (clazz + ": " + field .getName ());
140+ if (field .getName ().startsWith (AJC_MAGIC )) {
141+ return true ;
142+ }
143+ }
144+ return false ;
145+ }
146+
117147
118148 /**
119149 * Enum for AspectJ annotation types.
0 commit comments