(结合自定义注解,实现日志的处理)
1.引入依赖
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
</dependency>
2.创建自己的自定义注解
@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface BussinessLog {
/** 操作类型: 新增 修改 删除 ,赋值要采用枚举,便于后期日志的整理归档 **/
String operateType() default "";
/** 功能模块 来源: 最好采用菜单的唯一性标志,便于的归档 **/
String sourceList() default "";
/** 操作信息 **/
String msg() default "";
}
2.创建切面
@Slf4j
@Aspect
@Component
public class BusinessLogAspect {
//利用注解 配置织入点
@Pointcut("@annotation(com.qinzhy.mydemo.annotation.BussinessLog)")
public void annotationPointCut(){}
/**
* 后置通知
*/
@After("annotationPointCut()")
public void insertLogByAnnotion