|
@@ -7,6 +7,7 @@ import org.aspectj.lang.ProceedingJoinPoint;
|
|
import org.aspectj.lang.annotation.Around;
|
|
import org.aspectj.lang.annotation.Around;
|
|
import org.aspectj.lang.annotation.Aspect;
|
|
import org.aspectj.lang.annotation.Aspect;
|
|
import org.aspectj.lang.annotation.Pointcut;
|
|
import org.aspectj.lang.annotation.Pointcut;
|
|
|
|
+import org.springframework.core.annotation.Order;
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.web.context.request.RequestAttributes;
|
|
import org.springframework.web.context.request.RequestAttributes;
|
|
import org.springframework.web.context.request.RequestContextHolder;
|
|
import org.springframework.web.context.request.RequestContextHolder;
|
|
@@ -23,6 +24,7 @@ import lombok.extern.slf4j.Slf4j;
|
|
@Aspect
|
|
@Aspect
|
|
@Component
|
|
@Component
|
|
@Slf4j
|
|
@Slf4j
|
|
|
|
+@Order(1)
|
|
public class InterfaceLimitAspect {
|
|
public class InterfaceLimitAspect {
|
|
/**
|
|
/**
|
|
* 层切点
|
|
* 层切点
|
|
@@ -39,7 +41,7 @@ public class InterfaceLimitAspect {
|
|
HttpServletRequest request = sra.getRequest();
|
|
HttpServletRequest request = sra.getRequest();
|
|
if (!InterfaceLimitUtil.checkInterface(request,interfaceLimit.time(),interfaceLimit.value())){
|
|
if (!InterfaceLimitUtil.checkInterface(request,interfaceLimit.time(),interfaceLimit.value())){
|
|
log.error("接口拦截:{} 请求超过限制频率【{}次/{}ms】,IP为{}", request.getRequestURI(), interfaceLimit.value(), interfaceLimit.time(), request.getRemoteAddr());
|
|
log.error("接口拦截:{} 请求超过限制频率【{}次/{}ms】,IP为{}", request.getRequestURI(), interfaceLimit.value(), interfaceLimit.time(), request.getRemoteAddr());
|
|
- return ResponseVO.fail(null,"请求过于频繁,请稍后再试");
|
|
|
|
|
|
+ return ResponseVO.fail("请求过于频繁,请稍后再试");
|
|
}
|
|
}
|
|
// result的值就是被拦截方法的返回值
|
|
// result的值就是被拦截方法的返回值
|
|
ResponseVO result = (ResponseVO)pjp.proceed();
|
|
ResponseVO result = (ResponseVO)pjp.proceed();
|