When using Spring Coroutine AOP, if the @transactional annotation and a custom AOP are applied together without specifying an order in the Aspect, there is an issue where the custom AOP does not get applied.
@Service
class TargetService() {
private val log = KotlinLogging.logger { }
@Logging
@Transactional
suspend fun aop(): String {
delay(100)
log.info { "aop target method call" }
return "ok"
}
}
@Aspect
//@Order(1)
@Component
class LoggingAspect {
private val log = KotlinLogging.logger {}
@Around("@annotation(com.example.aopwithtransaction.aop.Logging)")
fun logging(joinPoint: ProceedingJoinPoint): Any? {
return mono {
log.info { "Aop Logging started" }
val result = joinPoint.proceed().let { result ->
if (result is Mono<*>) {
result.awaitSingleOrNull()
} else {
result
}
}
log.info { "Aop Logging completed" }
result
}
}
}
This is a simple example : https://github.com/backtony/spring-reactive-aop-transaction