Spring AOP(二)

注解

1、开启AOP注解

<aop:aspectj-autoproxy/>

2、@Aspect

在类上使用,声明该类是一个切面类

3、通知

@Before("execution(* com.mystudy.service.impl.*.*(..))")
@Before("pt1()")

(1)通知类型注解:@Before、@AfterReturning、@AfterThrowing、@After、@Around

(2)在通知类型内直接写切入点表达式或者引用切入点id

4、@Pointcut

@Pointcut("execution(* com.yaorange.service.impl.*.*(..))")
public void pt1(){}//通过空方法关联切入点表达式

纯注解

@Configuration 
@ComponentScan(basePackages="com.yaorange") 
@EnableAspectJAutoProxy //等同于在配置文件中配置<aop:aspectj-autoproxy/>
public class SpringConfiguration { }
原文地址:https://www.cnblogs.com/heibaimao123/p/13826171.html