Spring AOP和Reactor中的多个有序注释出现错误

问题描述

我对这两个注释分别进行了说明:

@Target(AnnotationTarget.FUNCTION)
@Retention(AnnotationRetention.RUNTIME)
annotation class BackupCache
@Target(AnnotationTarget.FUNCTION)
@Retention(AnnotationRetention.RUNTIME)
annotation class Cb(val circuitBreakerConfig: CircuitBreakerManager.CircuitBreakerConfigs) {}
@Aspect
@Component
class CircuitBreakerAnnotationAspect(meterRegistry: MeterRegistry? = null) {
    @Around("@annotation(cb)")
    fun aroundAnnotatedCBMethod(joinPoint: ProceedingJoinPoint,cb: Cb): Mono<*> {
        val signature = joinPoint.signature
        return wrap(signature,cb) {
            joinPoint.proceed() as Mono<*>
        }
    }
}

@Aspect
@Component
class BackupCacheAspect(@Autowired val backupCacheService: BackupCacheService) : Ordered {
    @Around("@annotation(backupCache)")
    fun aroundAnnotatedCBMethod(joinPoint: ProceedingJoinPoint,backupCache: BackupCache): Mono<ApiDataWrapper> {
       // ...
    }

    override fun getOrder(): Int = 1000
}

我需要使它们依次排列,Cb被称为最内层,BackupCache被称为最外层。如果我同时下达命令(使用Cb order = 10),则会出现以下错误:

java.lang.IllegalStateException: Required to bind 2 arguments,but only bound 1 (JoinPointMatch was NOT bound in invocation)

测试以再现:

@Component
class Many {
    @BackupCache
    @Cb(DEFAULT)
    fun methodWithAnnotations(id: String): Mono<ApiDataWrapper> {
        return Mono.empty()
    }
}
@SpringBootTest
class MultipleAnnotationsOnServicesTests {
    @Autowired
    lateinit var many: Many

    @Test
    fun testMultipleAnnotations(){
        StepVerifier.create(many.methodWithAnnotations("aaa"))
                .verifyComplete()
    }
}

删除命令之一可解决此问题,但我需要强制执行该命令。有人可以帮忙吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...