Aspect Oriented Programming 在不惊动原始设计的基础上为方法进行功能增强
导入坐标
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.9.4</version>
</dependency>
@Component
@Aspect
public class MyAdvice {
@Pointcut("execution(void dao.BookDao.update())")
private void pt(){}
@Before("pt()")
public void fn(){
System.out.println(System.currentTimeMillis());
}
}
@Configuration
@EnableAspectJAutoProxy
@ComponentScan({"dao","service","aop"})
public class SpringConfig {
}
环绕通知
@Around("pt()")
public Object aroundAdvice(ProceedingJoinPoint pjp) throws Throwable {
System.out.println("around before advice ...");
Object ret = pjp.proceed();
System.out.println("around after advice ...");
return ret;
}
切入点表达式
即定义切入点时,execution指定的 连接方法路径
.. 表示 任意,可以没有也可以任意多个
* 表示 任意一个
|