AspectJ表达式
常见格式: execution(再写其它内容) 表示匹配某个方法的执行
小括号中的其他内容,其实跟我们以前的方法声明语法差不多。只不过支持 * (通配符) 和 ..(表示任意参数)
public void *()
表示 所有无参的返回值类型是void的任意的public 方法。
public * com.example.spring.aop.service.impl.*Impl.*(..))
表示com.example.spring.aop.service.impl包下面,所有以Impl结尾的类中,所有public类型的方法。
public * com.example.spring.aop.service.impl.*Impl.m*(..))
表示com.example.spring.aop.service.impl包下面,所有以Impl结尾的类中,所有public类型的以m开头的方法。
public * com.example..service.impl.*Impl.m*(..)
表示com.example.service.impl包下面、
com.example.(任意层级).service.impl包下面,
所有以Impl结尾的类中,所有public类型的以m开头的方法。
参考资料:https://www.cnblogs.com/duanxz/p/5217689.html
增强方式
<aop:before> 表示前置增强
@Before
<aop:after-throwing>
@AfterThrowing
当目标方法执行过程中,抛出异常的时候会执行这里的逻辑。 要想捕获异常类型,可以使用Exception类型的