traceID
This commit is contained in:
@@ -1,20 +1,31 @@
|
||||
package com.czg.config;
|
||||
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import jakarta.servlet.*;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.slf4j.MDC;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author GYJoker
|
||||
*/
|
||||
@Configuration
|
||||
public class CorsFilter implements Filter {
|
||||
|
||||
@Value("${spring.application.name:unknown-service}")
|
||||
private String applicationName;
|
||||
@Override
|
||||
public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain)
|
||||
throws IOException, ServletException {
|
||||
// traceId
|
||||
Map<String, String> copyOfContextMap = MDC.getCopyOfContextMap();
|
||||
copyOfContextMap.put("traceId",applicationName + IdUtil.getSnowflakeNextId());
|
||||
MDC.setContextMap(copyOfContextMap);
|
||||
HttpServletResponse response = (HttpServletResponse) resp;
|
||||
HttpServletRequest reqs = (HttpServletRequest) req;
|
||||
String curOrigin = reqs.getHeader("Origin");
|
||||
|
||||
Reference in New Issue
Block a user