Closed
Description
Affects: 6.1.6
If you extend an aspect class and override its method, then this method will be called twice.
Example in kotlin:
import mu.KLogging
import org.aspectj.lang.ProceedingJoinPoint
import org.aspectj.lang.annotation.Around
import org.aspectj.lang.annotation.Aspect
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.stereotype.Component
annotation class CustomAnnotation()
@Aspect
open class CustomAnnotationAspect {
@Around("execution (@CustomAnnotation * *.*(..))")
open fun wrapExecution(pjp: ProceedingJoinPoint): Any? {
logger.info { "start in super class" }
val result = pjp.proceed()
logger.info { "start in super class" }
return result
}
companion object : KLogging()
}
@Aspect
class ExtendedCustomAnnotationAspect : CustomAnnotationAspect() {
// don't matter if same @Around annotation presents or not
override fun wrapExecution(pjp: ProceedingJoinPoint): Any? {
logger.info { "start" }
val result = pjp.proceed()
logger.info { "finish" }
return result
}
companion object : KLogging()
}
@Configuration
class Config {
@Bean
fun customAspect(): ExtendedCustomAnnotationAspect {
return ExtendedCustomAnnotationAspect()
}
}
then, when we call method annotated with @CustomAnnotation
, we get output in console:
start
start
target method execution
finish
finish
expected output:
start
target method execution
finish
The call of ReflectionUtils.doWithMethods(...)
in ReflectiveAspectJAdvisorFactory#getAdvisorMethods
collects all user declared methods (methods of superclass and overridden methods), and all of them are used for making an advisors.