问题描述
我对这两个注释分别进行了说明:
@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 (将#修改为@)