Spring-@Aspect 的使用

摘要:ssm框架学习
你想输入的替代文字

在ssm中AOP的使用
xml中
<-- 开启aop日志="" --="">
<aop:aspectj-autoproxy />

引入AOP
@Aspect
加入到IOC容器
@Component
指向自定义注解路径
@Pointcut(“@annotation(com.kxs.common.annotation.SysLog)”)
/定义一个方法, 用于声明切入点表达式. 一般地, 该方法中再不需要添入其他的代码.
使用 @Pointcut 来声明切入点表达式.
后面的其他通知直接使用方法名来引用当前的切入点表达式.
/
@Pointcut(“execution(public int com.aop.ArithmeticCalculator.*(int, int))”)

前置通知
@Before()
返回通知
@AfterReturning()
后置通知
@After()
异常通知
@AfterThrowing()
环绕通知:目标方法执行前后分别执行一些代码,发生异常的时候执行另外一些代码
@Around()
括号内容
value=”execution( com.qcc.beans.aop..*(..))”

@Before 比方:拦截service方法

  • 1.Before 在执行service方法之前,触发该方法
  • 2.After在执行service方法之后,触发该方法
  • 3.AfterThowing 在执行Service时抛出异常触发
  • 4.Around回绕通知,在之前,之后都会触发

用法
@Before(value = “execution ( com.service.impl..*(..))”)