自定义注解
aop/Monitor.java
import java.lang.annotation.*;
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD})
@Documented
public @interface Monitor {
String reportName() default "";
}
捕获切面
aop/MonitorAspect.java
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Aspect
@Component
public class MonitorAspect {
ThreadLocal<Long> startTime = new ThreadLocal<>();
@AutoWired
ReportService reportService;
@Pointcut("@annotation(monitor)")
public void monitorPointCut(Monitor monitor) {
}
@Before("monitorPointCut(monitor)")
public void