依赖
在pom中添加一下依赖:
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.9.1</version>
</dependency>
步骤
在这里我们把打印日志做一个切面。
关于AOP的理解可以看:https://blog.csdn.net/q982151756/article/details/80513340
1. 添加Configation类开启AOP的自动代理。
@Configuration
@EnableAspectJAutoProxy
public class LogConfigation {
}
@EnableAspectJAutoProxy这个注解就是开启AOP的自动代理。
2. 写一个注解
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface LogAnnotation {
String value() default "";
}
该注解表示生命周期是运行时也保存,且作用于方法。
关于注解可以看: