使用注解方式实现AOP
- @Aspect
- @Before(“execution(* * * *)”)
- @After(“execution(* * * *)”)
- @Around(“execution(* * * *)”)
xml文件配置
<bean id = "userService" class="com.xiaocheng.service.UserServiceImpl"/>
<bean id = "annotationPointCut" class="com.xiaocheng.diy.annotationPointCut"/>
<aop:aspectj-autoproxy/>
Java写法
@Aspect
public class annotationPointCut {
@Before("execution(* com.xiaocheng.service.UserServiceImpl.*(..))")
public void before(){
System.out.println("运行前");
}
@After("execution(* com.xiaocheng.service.UserServiceImpl.*(..))")
public void after(){
System.out.println("运行后");
}
@Around("execution(* com.xiaocheng.service.UserServiceImpl.*(..))")
public void around(ProceedingJoinPoint jp){
System.out.println("环绕前");
Object proceed = jp.proceed();
System.out.println("环绕后");
}
}