Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想使用 AOP 在我的方法中记录一些语句。
我能够定义切入点、方法开始、结束、异常场景的建议。
我们可以在某个时间点(在方法输入之后和执行完成之前)在方法之间登录吗?我使用的是 Spring 3.0。
不,这是不可能的。Spring 无法“查看”您的方法并对其进行修改。从技术上讲,AspectJ weaving 可以做到这一点,但我会远离这种方法。
您可以做的是提取方法,这不仅可以让您提供一些更细粒度的日志记录,还可以提高整体代码质量。但是请注意,默认情况下 Spring 只能拦截公共(代理)和受保护方法(CGLIB)。