aop的作用:再不更改源代码的基础上增强功能。
@Component
@Aspect
public class MyAdvice {
@Pointcut("execution(void com.itheima.*.BookDao.update())")
private void pt(){
}
@Before("pt()")
public void method(){
System.out.println(System.currentTimeMillis());
}
}
@Configuration//证明这个类是spring的配置文件类
@ComponentScan("com.itheima")//扫描的哪些包下有注解
@EnableAspectJAutoProxy
public class SpringConfig {
}
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>5.2.10.RELEASE</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.9.4</version>
</dependency>

浙公网安备 33010602011771号