【发布时间】:2013-05-12 06:26:59
【问题描述】:
我对 AOP 完全陌生。我需要建议来编写正确的切入点。我有一个包含所有服务类的服务包。所有的类都实现了Service 接口。这个接口有一个方法save(entity)。我的建议应该在每次service.save(entity) 方法抛出DataIntegrityViolationException 时执行。
这里是方面:
@Component
@Aspect
public class DIVExceptionHandler {
@AfterThrowing(pointcut = "execution(* myPackage.service.Service.save(*))", throwing = "ex")
public void handleException(JoinPoint joinPoint, DataIntegrityViolationException ex) {
//snipped
}
}
如Spring AOP documentation 中所述,我在CP 中有两个aspectj jar,并且我已将<aop:aspectj-autoproxy/> 添加到Spring 配置中,并且我正在使用组件扫描。在测试的日志中,我可以看到方面被检测为 aspetcj 方面:
DEBUG o.s.a.a.a.ReflectiveAspectJAdvisorFactory - Found AspectJ method...
所以我相信这不是配置问题,我的切入点表达是错误的。我也试过了
@AfterThrowing(pointcut = "execution(* myPackage.service.*.save(*))", throwing = "ex")
但这也没有用。
那么正确的切入点表达式是什么?
【问题讨论】:
标签: aspectj spring-aop