The issue can be illustrated as follows:
@Aspect
@Component
@Slf4j
public class OldApiAspect {
@Around("@within(com.top.plutus.common.OldApiService)")
public Object doSomething1(ProceedingJoinPoint pjp) throws Throwable {
return pjp.proceed();
}
@Around("@annotation(com.top.plutus.common.OldApiService)")
public Object doSomething2(ProceedingJoinPoint pjp) throws Throwable {
return pjp.proceed();
}
}
@OldApiService
public interface TestService {
@OldApi
String test1();
@OldApi
String test2();
}
If we add annotation only on the interface, aop would not work. Actually, by scanning the code, it has accounted for this situation. Version: Spring Framework 5.2.9.RELEASE
org.springframework.aop.support.AopUtils:
public static boolean canApply(Pointcut pc, Class<?> targetClass, boolean hasIntroductions) {
......
Set<Class<?>> classes = new LinkedHashSet<>();
if (!Proxy.isProxyClass(targetClass)) {
classes.add(ClassUtils.getUserClass(targetClass));
}
//here interfaces have been added to search range
classes.addAll(ClassUtils.getAllInterfacesForClassAsSet(targetClass));
}
org.springframework.aop.aspectj.AspectJExpressionPointcut:
private ShadowMatch getShadowMatch(Method targetMethod, Method originalMethod) {
// Avoid lock contention for known Methods through concurrent access...
ShadowMatch shadowMatch = this.shadowMatchCache.get(targetMethod);
....
}
As the spring codes tells, when the implemented class's method could not meet the condition, it would be directly into the cache. When the method of the interface(After being processed by getMostSpecificMethod would return the method located in the implemented class) arrives here, the match result comes from the cache instead of checking the interface. But the interface might be configured differently from the implemented class.
My question:
If not supported interface, why put interfaces to search range?
(classes.addAll(ClassUtils.getAllInterfacesForClassAsSet(targetClass));)
If support, the current logic is getMostSpecificMethod return the implemented method instead of the method located in interface. This might not work?
Comment From: QuantumXiecao
@sbrannen Hi, I want to fix this issue. Could you please assign this issue to me?
Comment From: sbrannen
Hi @QuantumXiecao,
The team has not yet had the opportunity to investigate this issue.
If you wish to submit a PR, you may do so but run the risk of the PR being rejected if the team decides not to address the issue.
I would therefore advise against submitting a PR until the team has come to a decision.
Comment From: snicoll
@QuantumXiecao we'd like to review this but we'd need a small sample that reproduces the problem. You can attach a zip to this issue or push the code to a separate GitHub repository. Thanks!
Comment From: spring-projects-issues
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.
Comment From: spring-projects-issues
Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.