|
1 | 1 | /* |
2 | | - * Copyright 2002-2023 the original author or authors. |
| 2 | + * Copyright 2002-2024 the original author or authors. |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
|
50 | 50 | import org.springframework.core.convert.converter.Converter; |
51 | 51 | import org.springframework.core.convert.converter.ConvertingComparator; |
52 | 52 | import org.springframework.lang.Nullable; |
| 53 | +import org.springframework.util.ClassUtils; |
53 | 54 | import org.springframework.util.ReflectionUtils; |
54 | 55 | import org.springframework.util.ReflectionUtils.MethodFilter; |
55 | 56 | import org.springframework.util.StringUtils; |
@@ -133,17 +134,19 @@ public List<Advisor> getAdvisors(MetadataAwareAspectInstanceFactory aspectInstan |
133 | 134 |
|
134 | 135 | List<Advisor> advisors = new ArrayList<>(); |
135 | 136 | for (Method method : getAdvisorMethods(aspectClass)) { |
136 | | - // Prior to Spring Framework 5.2.7, advisors.size() was supplied as the declarationOrderInAspect |
137 | | - // to getAdvisor(...) to represent the "current position" in the declared methods list. |
138 | | - // However, since Java 7 the "current position" is not valid since the JDK no longer |
139 | | - // returns declared methods in the order in which they are declared in the source code. |
140 | | - // Thus, we now hard code the declarationOrderInAspect to 0 for all advice methods |
141 | | - // discovered via reflection in order to support reliable advice ordering across JVM launches. |
142 | | - // Specifically, a value of 0 aligns with the default value used in |
143 | | - // AspectJPrecedenceComparator.getAspectDeclarationOrder(Advisor). |
144 | | - Advisor advisor = getAdvisor(method, lazySingletonAspectInstanceFactory, 0, aspectName); |
145 | | - if (advisor != null) { |
146 | | - advisors.add(advisor); |
| 137 | + if (method.equals(ClassUtils.getMostSpecificMethod(method, aspectClass))) { |
| 138 | + // Prior to Spring Framework 5.2.7, advisors.size() was supplied as the declarationOrderInAspect |
| 139 | + // to getAdvisor(...) to represent the "current position" in the declared methods list. |
| 140 | + // However, since Java 7 the "current position" is not valid since the JDK no longer |
| 141 | + // returns declared methods in the order in which they are declared in the source code. |
| 142 | + // Thus, we now hard code the declarationOrderInAspect to 0 for all advice methods |
| 143 | + // discovered via reflection in order to support reliable advice ordering across JVM launches. |
| 144 | + // Specifically, a value of 0 aligns with the default value used in |
| 145 | + // AspectJPrecedenceComparator.getAspectDeclarationOrder(Advisor). |
| 146 | + Advisor advisor = getAdvisor(method, lazySingletonAspectInstanceFactory, 0, aspectName); |
| 147 | + if (advisor != null) { |
| 148 | + advisors.add(advisor); |
| 149 | + } |
147 | 150 | } |
148 | 151 | } |
149 | 152 |
|
|
0 commit comments