@ -51,6 +51,7 @@ import org.springframework.core.convert.converter.Converter;
@@ -51,6 +51,7 @@ import org.springframework.core.convert.converter.Converter;
import org.springframework.core.convert.converter.ConvertingComparator ;
import org.springframework.lang.Nullable ;
import org.springframework.util.ReflectionUtils ;
import org.springframework.util.ReflectionUtils.MethodFilter ;
import org.springframework.util.StringUtils ;
import org.springframework.util.comparator.InstanceComparator ;
@ -70,7 +71,11 @@ import org.springframework.util.comparator.InstanceComparator;
@@ -70,7 +71,11 @@ import org.springframework.util.comparator.InstanceComparator;
@SuppressWarnings ( "serial" )
public class ReflectiveAspectJAdvisorFactory extends AbstractAspectJAdvisorFactory implements Serializable {
private static final Comparator < Method > METHOD_COMPARATOR ;
// Exclude @Pointcut methods
private static final MethodFilter adviceMethodFilter = ReflectionUtils . USER_DECLARED_METHODS
. and ( method - > ( AnnotationUtils . getAnnotation ( method , Pointcut . class ) = = null ) ) ;
private static final Comparator < Method > adviceMethodComparator ;
static {
// Note: although @After is ordered before @AfterReturning and @AfterThrowing,
@ -86,7 +91,7 @@ public class ReflectiveAspectJAdvisorFactory extends AbstractAspectJAdvisorFacto
@@ -86,7 +91,7 @@ public class ReflectiveAspectJAdvisorFactory extends AbstractAspectJAdvisorFacto
return ( ann ! = null ? ann . getAnnotation ( ) : null ) ;
} ) ;
Comparator < Method > methodNameComparator = new ConvertingComparator < > ( Method : : getName ) ;
METHOD_COMPARATOR = adviceKindComparator . thenComparing ( methodNameComparator ) ;
adviceMethodComparator = adviceKindComparator . thenComparing ( methodNameComparator ) ;
}
@ -160,15 +165,10 @@ public class ReflectiveAspectJAdvisorFactory extends AbstractAspectJAdvisorFacto
@@ -160,15 +165,10 @@ public class ReflectiveAspectJAdvisorFactory extends AbstractAspectJAdvisorFacto
}
private List < Method > getAdvisorMethods ( Class < ? > aspectClass ) {
final List < Method > methods = new ArrayList < > ( ) ;
ReflectionUtils . doWithMethods ( aspectClass , method - > {
// Exclude pointcuts
if ( AnnotationUtils . getAnnotation ( method , Pointcut . class ) = = null ) {
methods . add ( method ) ;
}
} , ReflectionUtils . USER_DECLARED_METHODS ) ;
List < Method > methods = new ArrayList < > ( ) ;
ReflectionUtils . doWithMethods ( aspectClass , methods : : add , adviceMethodFilter ) ;
if ( methods . size ( ) > 1 ) {
methods . sort ( METHOD_COMPARATOR ) ;
methods . sort ( adviceMethodComparator ) ;
}
return methods ;
}