-
Notifications
You must be signed in to change notification settings - Fork 38.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot call Kotlin suspend function in @Around
advice after Spring Framework 6.1
#31855
Comments
Can you please provide a reproducer as an attached archive or a link to a repsoitory? |
@sdeleuze https://github.com/T45K/spring-aop-around-repro please take a look 🙏 |
ah, i found a solution by myself @Component
@Aspect
class Aspect {
@Around("xxx")
fun execute(joinPoint: ProceedingJoinPoint): Any? = mono {
callSuspendFunction()
}.then(joinPoint.proceed() as Mono<*>)
} this looks working fine |
Yeah, your solution looks fine. Before Spring Framework 6.1, there was no support for Coroutines in Spring AOP, so you had to invoke the suspending function manually like you did in your repro. As of Spring Framework 6.1, suspending functions are translated to their Reactive equivalent, as shown by your comment above. |
thank you for answering. i have another question. // return Mono directly as Before advice
@Before("...")
fun execute(joinPoint): Any? = mono {
callSuspendFunction()
}
// or, use suspend function directly as Before advice
@Before("...")
suspend fun execute(joinPoint): Any {
callSuspendFunction()
} |
I will discuss that with the team and let you know. |
We don't plan to add Coroutines dedicated support for the use cases mentioned in this comment since it would likely require, as far as I can tell, AspectJ support for Coroutines and/or Reactor which is unlikely to happen. If you think that would be useful, we can review a related documentation PR for Kotlin documentation that would provide guidance for AspectJ + Coroutines for Spring use case. |
i see. thank you |
@sdeleuze I was looking for a way to manipulate coroutine context in an advice, as it would be quite handy in order to let I managed to hack something together without this support for now: ObservedSuspendingAspect, but I am wondering if this is the way to go for each and every aspect that ends up needing to manipulate coroutine context. |
Affects: <Spring Framework version>
We used this workaround to execute suspend function in advice.
But, after updating Spring Boot to 3.2.0,
ClassCastException
occurs.stack trace
Details
I guess this is due to updating
AopUtils
, which callsCoroutinesUtils
.I know this is really workaround way to invocate suspend function in AOP advice, so I can't help but think there are problems when updating the libraries.
Do you know another way to invocate suspend function in AOP advice?
Thank you.
The text was updated successfully, but these errors were encountered: