注解实现AOP
applicationContext.xml
<!--方法三:注解支持-->
<bean id="point" class="com.shao.diy.PointCut"/>
<aop:aspectj-autoproxy/>
package com.shao.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;
//标注这个类是一个切面
@Aspect
public class PointCut {
@Before("execution(* com.shao.service.UserServiceImpl.*(..))")
public void before(){
System.out.println("-------开始前-------");
}
@After("execution(* com.shao.service.UserServiceImpl.*(..))")
public void after(){
System.out.println("-------结束后-------");
}
//在环绕中,我们可以给定一个参数,代表我们要处理的介入的点
@Around("execution(* com.shao.service.UserServiceImpl.*(..))")
//与切入点匹配的连接点
public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
System.out.println("-------环绕前-------");
Object proceed = joinPoint.proceed();
System.out.println("-------环绕后-------");
return proceed;
}
}
主要是给自己看的,所以肯定会出现很多错误哈哈哈哈哈

浙公网安备 33010602011771号