Spring AOP切面声明方式

Spring AOP切面声明方式有注解和xml方式。

第一种:XML中声明切面

AOP配置元素 用 途

<aop:advisor> 定义AOP通知器

<aop:after> 定义AOP后置通知(不管被通知的方法是否执行成功)

<aop:after- returning> 定义AOP返回通知

<aop:after- throwing> 定义AOP异常通知

<aop:around> 定义AOP环绕通知

<aop:aspect> 定义一个切面

<aop:aspectj- autoproxy> 启用@AspectJ注解驱动的切面

<aop:before> 定义一个AOP前置通知

<aop:config> 顶层的AOP配置元素。大多数的<aop:*>元素必须包含 在<aop:config>元素内

<aop:declare- parents> 以透明的方式为被通知的对象引入额外的接口

<aop:pointcut> 定义一个切点

先定义一个简单类

再在XML中声明切面

第二种:使用注解方式

经验分享 程序员 微信小程序 职场和发展