一、步骤
(下面演示我用的applicationContext-aop.xml啥名都行的,测试对应起来就行)
① 导入 AOP 相关坐标(在pom.xml)
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.0.3.RELEASE</version>
</dependency>
<!-- aspectj的织入 -->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.8.13</version>
</dependency>
② 创建目标接口和目标类(内部有切点)
package cn.itcast.aop;
/**
* @author QLBF
* @version 1.0
* @date 2021/1/12 19:56
*/
public interface TargetInterface {
public void save();
}
package cn.itcast.aop;
/**
* @author QLBF
* @version 1.0
* @date 2021/1/12 19:57
*/
public class Target implements TargetInterface {
public void save() {
System.out.println("aop_xml run...");
}
}
③ 创建切面类(内部有增强方法)
package cn.itcast.aop;
/**
* @author QLBF
* @version 1.0
* @date 2021/1/13 9:39
*/
public class MyAspect {
public void before(){
System.out.println("前置增强...");
}