2

I have these two annotation with their respective aspects:

@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<*>
        }
    }
}

and

@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
}

I need them to be in order, Cb to be called innermost and BackupCache outermost. If I put ordered to both (with Cb order = 10) this will break with the following error:

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

Test to repro:

@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()
    }
}

removing one of the ordered fixes the problem, but I need the order to be enforced. Can anyone help?

kriegaex
  • 63,017
  • 15
  • 111
  • 202
gotch4
  • 13,093
  • 29
  • 107
  • 170

0 Answers0