spring - 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()
}
}
删除其中一个命令可以解决问题,但我需要执行命令。任何人都可以帮忙吗?
解决方案
推荐阅读
- firebase - 用于 Unity 的 Firebase 实时数据库中的增量值
- python - pandas.read_csv:如何将 2 组两列解析为日期时间并命名解析的列
- c++ - 具有不同指向成员的参数的非类型模板参数的特化是否保证是唯一的特化?
- c - 为什么用 %d 打印字符变量会在 c 中给出负值?
- c - 在 C 中将控制台拆分为两个不同的部分
- python - Nonetype错误/没有使用beautifulsoup for python打印的元素
- mysql - 关于 MySql 使用键删除
- docker - 如何使用扩展锚向 docker compose 添加变量?
- wpf - 目标类型与元素类型不匹配,控件不会显示在设计器中
- assembly - (mips64) lw 和 sw 不向寄存器添加值