Skip to content

Commit 791084d

Browse files
committed
refactor: 只记录api请求
1 parent 21f1478 commit 791084d

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

hsweb-logging/hsweb-access-logging-aop/src/main/java/org/hswebframework/web/logging/aop/AopAccessLoggerSupport.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
import org.springframework.beans.factory.annotation.Autowired;
1515
import org.springframework.context.ApplicationEventPublisher;
1616
import org.springframework.core.Ordered;
17+
import org.springframework.core.annotation.AnnotatedElementUtils;
1718
import org.springframework.util.ClassUtils;
19+
import org.springframework.web.bind.annotation.RequestMapping;
1820

1921
import javax.servlet.http.HttpServletRequest;
2022
import java.lang.reflect.Method;
@@ -107,6 +109,9 @@ public int getOrder() {
107109

108110
@Override
109111
public boolean matches(Method method, Class<?> aClass) {
112+
if(null == AnnotatedElementUtils.findMergedAnnotation(method, RequestMapping.class)){
113+
return false;
114+
}
110115
return loggerParsers.stream().anyMatch(parser -> parser.support(aClass, method));
111116
}
112117
}

hsweb-logging/hsweb-access-logging-aop/src/main/java/org/hswebframework/web/logging/aop/ReactiveAopAccessLoggerSupport.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@
1616
import org.springframework.beans.factory.annotation.Autowired;
1717
import org.springframework.context.ApplicationEventPublisher;
1818
import org.springframework.core.Ordered;
19+
import org.springframework.core.annotation.AnnotatedElementUtils;
1920
import org.springframework.core.annotation.AnnotationUtils;
2021
import org.springframework.http.server.reactive.ServerHttpRequest;
2122
import org.springframework.util.ClassUtils;
2223
import org.springframework.util.ConcurrentReferenceHashMap;
24+
import org.springframework.web.bind.annotation.RequestMapping;
2325
import org.springframework.web.server.ServerWebExchange;
2426
import org.springframework.web.server.WebFilter;
2527
import org.springframework.web.server.WebFilterChain;
@@ -209,7 +211,10 @@ public boolean matches(@Nonnull Method method, @Nonnull Class<?> aClass) {
209211
if (!Publisher.class.isAssignableFrom(method.getReturnType())) {
210212
return false;
211213
}
212-
214+
// 只记录API请求
215+
if(null == AnnotatedElementUtils.findMergedAnnotation(method, RequestMapping.class)){
216+
return false;
217+
}
213218
AccessLogger ann = AnnotationUtils.findAnnotation(method, AccessLogger.class);
214219
if (ann != null && ann.ignore()) {
215220
return false;

0 commit comments

Comments
 (0)