似乎AOP不适用于Reactive设置。
我写了一个方面,应该捕获反应性函数的结果并将其进一步发送。当我突然运行测试时,我开始遇到以前从未有过的Mongo错误:
org.springframework.dao.DuplicateKeyException: E11000 duplicate key error collection
这是我的方面。它仅进行一些检查并发送结果。无需接触数据库。
@Retention(AnnotationRetention.RUNTIME)
annotation class SpecialAnnotation
@Aspect
@Component
class MyAspect(val sender: MySender) {
@AfterReturning(pointcut = "@annotation(SpecialAnnotation)", returning = "result")
fun send(joinPoint: JoinPoint, result: Any) {
(result as Mono<MyResult>)
.map { sender.send(result) }
.subscribe()
}
}
这就是我的称呼:
@Component
class MyJoinPoint {
@SpecialAnnotation
fun getResult(): Mono<Result> {....}
}
如果方面注释或订阅已删除,问题就不存在了。当然,这不是我期望的结果。
我应该为此使用特殊的AOP反应版本吗?有没有其他选择? DB错误可能是什么问题?