通过AOP拦截接口请求,计算接口访问时间,并存入数据库从而统计程序所有接口的访问效率,从而达到针对性优化策略,下面我直接通过代码进行讲解。
package com.wk.zh.admin.constants;
import com.alibaba.fastjson.JSONArray;
import com.wk.zh.admin.model.SysInterfaceLog;
import com.wk.zh.admin.service.SysInterfaceLogService;
import com.wk.zh.common.utils.HNUtil;
import com.wk.zh.common.web.RequestLocalHelper;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.Date;
@Aspect
@Component