Open cdfive opened 5 years ago
I'm afraid there is not much we can do about this on Spring's side since those annotation checks are performed by AspectJ itself which focuses on the concrete class to be weaved and generally follows Java language semantics where interface-declared annotations are not inherited.
Reopening again after re-reading the details and noticing that the AspectJ compiler does seem to behave differently there. We should investigate how it does that, maybe we can imitate that via custom ShadowMatch
checks indeed.
Any advancement on this ?
it would be amazing to be able to listen to annotated methods from interfaces'
Also in need
In need aswell!
@Around("@annotation(myAnnotation)")
public Object aroundMyAnnotation(
ProceedingJoinPoint proceedingJoinPoint, myAnnotation annotation) throws Throwable {
...
}
Affects: spring-aop:5.0.9.RELEASE, spring-boot-starter-aop:2.0.5.RELEASE
Using
spring-aop
like the code above, it doesn't work,around(ProceedingJoinPoint pjp)
never executes.If put the
@MyAnnotation
on the implemented method ofFooServiceImpl
, it works.Learned from two questions in Stack Overflow:
According to the Java 5 specification, non-type annotations are not inherited, and annotations on types are only inherited if they have the
@Inherited
meta-annotation.It's seems that it's impossible in
spring-aop
.I tried the code without
spring-aop
, only usingaspectjweaver
1.7.4, and adding anaop.xml
inresources/META-INF
:and adding JVM parameter:
-javaagent:xxx/aspectjweaver-1.7.4.jar
It works no matter the
@MyAnnotation
is on the interface or class. And then inaround(ProceedingJoinPoint pjp)
, I can get the@MyAnnotation
with the API of pjp, like this:or
So I think
spring-aop
may also have way to solve this problem, since it's a common use case for users to add annotation on the method of interface.Something in
AopUtils#getMostSpecificMethod
,AspectJExpressionPointcut#getShadowMatch(Method targetMethod, Method originalMethod)
may be about, I'm not sure.Could you please give some help?