使用注解的方式
1.自定义注解类
package com.yyf.div;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;
@Component
@Aspect //标注这个类是切面
public class AnnotationPointCut {
@Before ("execution(* com.yyf.service.ServiceImpl.*(..))") //切入点
public void before() {
System.out.println ("==========方法执行前=====");
}
@After ("execution(* com.yyf.service.ServiceImpl.*(..))") //切入点
public void after(){
System.out.println ("==========方法执行后=====");
}
@Around ("execution(* com.yyf.service.ServiceImpl.*(..))")
public void around(ProceedingJoinPoint pj) throws Throwable {
System.out.println ("环绕前");
Signature signature = pj.getSignature ();//获得签名,也就是执行了什么包下的什么方法
System.out.println ("signature="+signature);
Object proceed = pj.proceed (); //执行方法
System.out.println ("环绕后");
System.out.println ("proceed="+proceed);
}
}
2.配置文件



