【发布时间】:2021-05-28 19:29:16
【问题描述】:
我正在编写一个注释,它应该在执行函数之前对 MessageId 执行一些验证。
@Aspect
@Component
class ValidatorAspect {
@Before("@annotation(whatever.Validator)")
fun checkMessage(joinPoint: JoinPoint) {
val messageId = joinPoint.args[1] as String
// run some validations
// if any validation fails, this should stop execution
// and annotated function not be called
}
}
我的函数注释为:
@Validator
@SqsListener("myqueue")
fun run(message: String) {
// code to proccess message
}
订单被正确调用:首先 SqsListener 接收消息,然后我的验证器应该在带注释的函数之前执行。
如何从run() 强制停止执行?如果任何验证失败,我不希望调用该带注释的类 - 另外,我不想抛出异常,我正在寻找平滑的东西,停止,没有异常:)
我尝试使用@Around,但我的建议在我的函数run()之后被调用
有什么想法或建议吗?
【问题讨论】:
标签: java kotlin aop spring-aop