简体   繁体   English

Spring AOP:在Around 建议中,我可以多次调用proceed() 吗?

[英]Spring AOP: In an Around advice, can I call proceed() multiple times?

I am reading through some Spring AOP course and I have just a short question: What would happen if inside of an @Around advice I would do multiple calls to proceed() on the ProceedingJoinPoint ?我正在阅读一些 Spring AOP 课程,我只有一个简短的问题:如果在@Around建议中我会在ProceedingJoinPoint上多次调用proceed()会发生什么? There would simply be multiple method invocations?只会有多个方法调用? Unfortunately, I have no possibility to test it right now.不幸的是,我现在无法测试它。

As the objective of AOP is to wrap additional logic around your own in order to achieve arbitrary goals, theoretically it should be possible to do what you ask and I do believe there may even be legitimate uses for it (like automatically wiring logic to do multiple attempts on "best effort" services).由于 AOP 的目标是围绕您自己的逻辑包装额外的逻辑以实现任意目标,因此理论上应该可以按照您的要求进行操作,我相信它甚至可能有合法用途(例如自动连接逻辑以执行多个操作)尝试“尽力而为”的服务)。

You will however have to be very careful in setting up such a mechanism as you may end up calling multiple times methods that ARE NOT meant to be called multiple times.但是,您在设置这种机制时必须非常小心,因为您最终可能会多次调用不打算多次调用的方法。 Make sure your Pointcut is VERY strict.确保您的切入点非常严格。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM