Aspectj 下载 传送门
下载后双击aspectj-1.9.5进行安装,一直点击next直到finish。
IDEA设置
添加完成后就可以操作Aspectj了。
引用demo
package Aop;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;
import java.util.Arrays;
import java.util.List;
import static myprint.Print.*;
/**
*把这个类声明一个切面:需要把该类放入到IOC容器中、在声明一个切面
*/
@Aspect
@Component
public class LoggingAspect {
//声明该方法是一个前置通知
@Before("execution(public int Aop.ArithmeticCalculatorImpl.*(int,int ))")
public void beforeMethod(JoinPoint joinPoint){
String methodName = joinPoint.getSignature().getName();
List<Object> args = Arrays.asList(joinPoint.getArgs());
println("The method begins"+args );
}
}