如何解决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 举报,一经查实,本站将立刻删除。