切面类:
package com.kuang.diy;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
// 方式三 :使用注解方式实现AOP
@Aspect//标注这个类是一个切面
public class AnnotationPointCut {
@Before("execution(* com.kuang.services.ServiceImpl.*(..))")
public void before(){
System.out.println("-----方法执行前-----");
}
@After("execution(* com.kuang.services.ServiceImpl.*(..))")
public void after(){
System.out.println("-----方法执行后-----");
}
@Around("execution(* com.kuang.services.ServiceImpl.*(..))")
public void around(ProceedingJoinPoint joinPoint) throws Throwable {
System.out.println("环绕前");
joinPoint.proceed();
System.out.println("环绕后");
}
}
xml
<!-- 方法三:使用注解实现AOP -->
<bean id="pointcut" class="com.kuang.diy.AnnotationPointCut"/>
<!-- 开启注解支持 -->
<!-- 自动代理 -->
<aop:aspectj-autoproxy/>