Spring13_基于注解实现AOP
-
将接口实现类和切面类交给IOC管理
-
切面类用@aspect[]注解标识为一个切面类
-
开启AOP
-
在切面类中的通知前添加注解
-
例如前置通知
@Before("execution(public int com.canyan7n.spring.aop.annotation.CalculatorImpl.add(int,int))") -
execution中包含修饰符 返回值 类的全路径+方法名,方法名中有参数列表
-
-
获取代理类对象,也可以获取实现的接口
-
切入点表达式
@Before("execution(public int com.canyan7n.spring.aop.annotation.CalculatorImpl.add(int,int))")@Before("execution(* com.canyan7n.spring.aop.annotation.Calculator.*(..))") - 第一个*表示修饰符和返回值 - 第二个*表示前面的包下的所有类或者类下的所有方法 - 括号里的..表示匹配所有参数 -
获取连接点的信息
JoinPoint对象
-
获取方法名
String name = joinPoint.getSignature().getName(); -
获取参数
Object[] args = joinPoint.getArgs();
-
-
重用切入点
@PointCut(“execution(* com.canyan7n.spring.aop.annotation.CalculatorImpl.*(…))”)


370

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



