Webflux-Aop:Aspect 中的 Get 方法请求(Mono)class
Webflux-Aop:Get method request(Mono) in Aspect class
我正在尝试编写一个方面,它负责在调用服务实现之前调用一些外部系统 classes。
我很难获得方面的方法请求 class.Any 帮助将不胜感激。我试着写如下,但没有运气在 class.
方面获得 Mono Object
方法
@someAnnotation
@PutMapping
fun getAccounts(
@RequestParam(name = "someParam")
someParam: String?,
@ModelAttribute
request: Mono<Request>,
): Mono<Response>{
return response;
}
注释
@Target(AnnotationTarget.FUNCTION)
@Retention(AnnotationRetention.RUNTIME)
annotation class someAnnotation(
val api: String,
)
看点:
@Aspect
@Component
@Order(0)
class SomeAspect{
@Suppress("UNCHECKED_CAST")
@Around("@annotation(someAnnotation)&&args(req,..)")
@Throws(Throwable::class)
fun <T> getResponse(joinPoint: ProceedingJoinPoint,apiReq : Mono<T>): Mono<T> {
val target = joinPoint.target
val methodSignature = joinPoint.signature as MethodSignature
val method: Method = methodSignature.method
val flux: Mono<T> = joinPoint.proceed() as Mono<T>
val methodArgs = joinPoint.args
//How to get request: Mono<Request> here????
return flux.flatMap { it ->
val req = it as someObject
//do something here........
}
}
}
对方面代码进行以下修改将解决该问题。 OP 想要建议一个具有多个参数的方法,并且建议主体可用的所需参数将是最后一个参数。
通过此处的评论总结决议。
@Aspect
@Component
@Order(0)
class SomeAspect{
@Suppress("UNCHECKED_CAST")
@Around("@annotation(someAnnotation) && args(..,apiReq)")
@Throws(Throwable::class)
fun <T> getResponse(joinPoint: ProceedingJoinPoint,apiReq : Mono<T>): Mono<T> {
val target = joinPoint.target
val methodSignature = joinPoint.signature as MethodSignature
val method: Method = methodSignature.method
val flux: Mono<T> = joinPoint.proceed() as Mono<T>
val methodArgs = joinPoint.args
//.. apiReq will refer to the required argument
return flux.flatMap { it ->
val req = it as someObject
//do something here........
}
}
}
我正在尝试编写一个方面,它负责在调用服务实现之前调用一些外部系统 classes。
我很难获得方面的方法请求 class.Any 帮助将不胜感激。我试着写如下,但没有运气在 class.
方面获得 Mono Object方法
@someAnnotation
@PutMapping
fun getAccounts(
@RequestParam(name = "someParam")
someParam: String?,
@ModelAttribute
request: Mono<Request>,
): Mono<Response>{
return response;
}
注释
@Target(AnnotationTarget.FUNCTION)
@Retention(AnnotationRetention.RUNTIME)
annotation class someAnnotation(
val api: String,
)
看点:
@Aspect
@Component
@Order(0)
class SomeAspect{
@Suppress("UNCHECKED_CAST")
@Around("@annotation(someAnnotation)&&args(req,..)")
@Throws(Throwable::class)
fun <T> getResponse(joinPoint: ProceedingJoinPoint,apiReq : Mono<T>): Mono<T> {
val target = joinPoint.target
val methodSignature = joinPoint.signature as MethodSignature
val method: Method = methodSignature.method
val flux: Mono<T> = joinPoint.proceed() as Mono<T>
val methodArgs = joinPoint.args
//How to get request: Mono<Request> here????
return flux.flatMap { it ->
val req = it as someObject
//do something here........
}
}
}
对方面代码进行以下修改将解决该问题。 OP 想要建议一个具有多个参数的方法,并且建议主体可用的所需参数将是最后一个参数。
通过此处的评论总结决议。
@Aspect
@Component
@Order(0)
class SomeAspect{
@Suppress("UNCHECKED_CAST")
@Around("@annotation(someAnnotation) && args(..,apiReq)")
@Throws(Throwable::class)
fun <T> getResponse(joinPoint: ProceedingJoinPoint,apiReq : Mono<T>): Mono<T> {
val target = joinPoint.target
val methodSignature = joinPoint.signature as MethodSignature
val method: Method = methodSignature.method
val flux: Mono<T> = joinPoint.proceed() as Mono<T>
val methodArgs = joinPoint.args
//.. apiReq will refer to the required argument
return flux.flatMap { it ->
val req = it as someObject
//do something here........
}
}
}