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