Code Monkey home page Code Monkey logo

Comments (5)

dadiyang avatar dadiyang commented on June 17, 2024

需要添加新的切面可以自己扩展

若需要切入除本项目提供的切面之外的其他切面,可以继承 AbstractCommonLogAspect 类,并实现 pointcut() 方法声明自己的切点

可参考 ServiceLogAspect、MapperLogAspect 和 RepositoryLogAspect 的实现

from autologging.

forest-wr avatar forest-wr commented on June 17, 2024

目前没有想到什么合适的方式
有一种是将清理threadLocal的工作放在自定义 HandlerInterceptor 的 afterCompletion 中,但是这种会丧失mq回调时threadLocal的清理工作

因为如果我自定义了 @RestControllerAdvice 的注解也没什么用
例如
func(){
a(); // Controller
b(); // RestControllerAdvice
}
再执行到b()的时候a方法已经执行结束了,到b就会重新生成了traceId

不知道大佬有没有好的方式可以解决这个问题😂

from autologging.

dadiyang avatar dadiyang commented on June 17, 2024

我没有完全理解你遇到的问题,可以把问题讲得详细一些吗?最好有些代码实例

from autologging.

forest-wr avatar forest-wr commented on June 17, 2024

假设为get请求
org.springframework.web.servlet.DispatcherServlet#doDispatch
function doDispatch(){
try{
handle(); // 会执行controller中的方法
}catch(exception e){
...
}
processDispatchResult(e); // 如果有异常会执行RestControllerAdvice中对应异常的方法
}

比方说 我们同时定义了这两个切面,那么
1.handle()方法执行,生成traceId,栈深度+1
2.handle()方法结束, 栈深度-1 = 0,清理了traceid,
3.processDispatchResult()方法执行,此时就会重新生成traceId

请问有没有什么方式可以解决这个问题(我能想到的是使用切面包裹住最外面的方法,但是不知道如何实施)

from autologging.

dadiyang avatar dadiyang commented on June 17, 2024

直接切doDispatch可以解决这个问题吗

from autologging.

Related Issues (7)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.