Spring AOP 与 Spring 架构命名空间详解
1. AOP 性能监控
在应用开发中,对方法性能和可能出现的异常进行监控是很重要的。在性能监控切面( PerformanceMonitoringAspect )中,我们会记录方法的性能和异常信息。
性能监控切面需要前置通知( @Before )和后置通知( @After )。前置通知用于记录方法调用的开始,后置通知则用于匹配并移除开始记录。这里不使用环绕通知( @Around )是因为我们需要在方法仍在运行时就发现某个特定方法的执行时间比平时长很多。如果使用环绕通知,我们只有在方法完成后才能发现其执行时间过长。
以下是性能监控切面的实现示例:
@Aspect
public class PerformanceMonitoringAspect {
@Pointcut("execution(* com.apress.prospring2.ch06.services.*.*(..))")
private void serviceCall() { }
@Before(value = "serviceCall() && target(target)",
argNames = "jp, target")
public void logStartCall(JoinPoint jp, Object target) {
// log start call
超级会员免费看
订阅专栏 解锁全文
168万+

被折叠的 条评论
为什么被折叠?



