traceId 问题

This commit is contained in:
wangw 2025-11-07 14:50:06 +08:00
parent e87f8f47b1
commit 185d3ba433
4 changed files with 13 additions and 10 deletions

View File

@ -54,6 +54,7 @@ public class ControllerAspect {
if(params.contains("jndi:rmi:")){
throw new RuntimeException("gun");
}
Map<String, String> contextMap = MDC.getCopyOfContextMap();
// 执行被拦截的方法
Object result = pjp.proceed();
long end = System.currentTimeMillis();
@ -63,7 +64,6 @@ public class ControllerAspect {
String requestIp = ServletUtil.getClientIP(request);
long useTime = end - start;
Map<String, String> contextMap = MDC.getCopyOfContextMap();
ThreadUtil.execAsync(() -> {
if (contextMap != null) {
MDC.setContextMap(contextMap);

View File

@ -1,7 +1,6 @@
package com.czg.config;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil;
import jakarta.servlet.*;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
@ -39,6 +38,12 @@ public class CorsFilter implements Filter {
response.setHeader("Access-Control-Max-Age", "3600");
response.setHeader("Access-Control-Allow-Headers", "token,Origin, X-Requested-With, Content-Type, Accept,shopId");
response.setHeader("Access-Control-Allow-Credentials", "true");
chain.doFilter(req, resp);
try {
// 原有 MDC 设置逻辑...
chain.doFilter(req, resp);
} finally {
// 清理当前线程的 traceId
MDC.remove("traceId");
}
}
}

View File

@ -2,8 +2,8 @@ package com.czg.config;
import cn.hutool.core.util.StrUtil;
import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.rpc.*;
import org.apache.dubbo.common.extension.Activate;
import org.apache.dubbo.rpc.*;
import org.slf4j.MDC;
/**
@ -22,11 +22,6 @@ public class TraceProviderFilter implements Filter {
// 设置到 MDC
MDC.put("traceId", traceId);
try {
return invoker.invoke(invocation);
} finally {
MDC.clear();
}
return invoker.invoke(invocation);
}
}

View File

@ -119,6 +119,9 @@ public class ShopInfoServiceImpl extends ServiceImpl<ShopInfoMapper, ShopInfo> i
if (isHeadShop != null) {
queryWrapper.eq(ShopInfo::getIsHeadShop, isHeadShop);
}
CzgResult<SysParamsDTO> shopOrderPayBaseUrl = sysParamsService.getParamsByCode("shop_order_pay_base_url");
CzgResult<SysParamsDTO> shopOrderPayBaseUrl2 = sysParamsService.getParamsByCode("ali_account_app_id");
List<ShopInfo> shopAllList = getMapper().selectListByQuery(query().select(ShopInfo::getId, ShopInfo::getShopName));
Map<Long, String> shopKv = shopAllList.stream().collect(Collectors.toMap(ShopInfo::getId, ShopInfo::getShopName));
queryWrapper.orderBy(ShopInfo::getCreateTime, false);