Skip to content

Commit 3e63951

Browse files
committed
relaxed @AspectJ detection check (for CGLIB subclasses to still be recognized as an aspect)
1 parent 56a4827 commit 3e63951

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

org.springframework.aop/src/main/java/org/springframework/aop/aspectj/annotation/AbstractAspectJAdvisorFactory.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,11 @@ protected AbstractAspectJAdvisorFactory() {
112112
* when compiled by ajc with the -1.5 flag, yet they cannot be consumed by Spring AOP.
113113
*/
114114
public boolean isAspect(Class<?> clazz) {
115-
return (AjTypeSystem.getAjType(clazz).isAspect() &&
116-
hasAspectAnnotation(clazz) && !compiledByAjc(clazz));
115+
return (hasAspectAnnotation(clazz) && !compiledByAjc(clazz));
117116
}
118117

119118
private boolean hasAspectAnnotation(Class<?> clazz) {
120-
return clazz.isAnnotationPresent(Aspect.class);
119+
return (AnnotationUtils.findAnnotation(clazz, Aspect.class) != null);
121120
}
122121

123122
/**

org.springframework.aop/src/main/java/org/springframework/aop/aspectj/annotation/AspectMetadata.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2006 the original author or authors.
2+
* Copyright 2002-2009 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -67,13 +67,23 @@ public class AspectMetadata {
6767
* @param aspectClass the aspect class
6868
* @param aspectName the name of the aspect
6969
*/
70-
public AspectMetadata(Class aspectClass, String aspectName) {
70+
public AspectMetadata(Class<?> aspectClass, String aspectName) {
7171
this.aspectName = aspectName;
72-
this.ajType = AjTypeSystem.getAjType(aspectClass);
73-
74-
if (!this.ajType.isAspect()) {
72+
73+
Class<?> currClass = aspectClass;
74+
AjType ajType = null;
75+
while (!currClass.equals(Object.class)) {
76+
AjType ajTypeToCheck = AjTypeSystem.getAjType(currClass);
77+
if (ajTypeToCheck.isAspect()) {
78+
ajType = ajTypeToCheck;
79+
break;
80+
}
81+
currClass = currClass.getSuperclass();
82+
}
83+
if (ajType == null) {
7584
throw new IllegalArgumentException("Class '" + aspectClass.getName() + "' is not an @AspectJ aspect");
7685
}
86+
this.ajType = ajType;
7787
if (this.ajType.getDeclarePrecedence().length > 0) {
7888
throw new IllegalArgumentException("DeclarePrecendence not presently supported in Spring AOP");
7989
}

0 commit comments

Comments
 (0)