我可以如下指定log4j格式化程序以在Spring MVC应用程序中打印当前线程ID
log4j.appender.FILE.layout.ConversionPattern=%d{ISO8601} %p %t %c - %m%n
如何在Spring应用程序中以编程方式获取当前线程ID。更准确地说,我想在拦截 Controller 方法的方面获取当前线程ID。我的方面如下:
@Configurable
@Aspect
public class TimingAspect {
@Autowired
private HttpServletRequest httpServletRequest;
//Generic performance logger for any mothod
private Object logPerfomanceInfo(ProceedingJoinPoint joinPoint) {
// do something with thread id
// do something with httprequest
...
}
// Performance info for API calls
@Around("execution(* package.controller.*.*(..))")
public Object logAroundApis(ProceedingJoinPoint joinPoint) throws Throwable {
return logPerfomanceInfo(joinPoint);
}
}
最佳答案
希望我能正确理解您的问题,这就是您要查找的内容:
Thread.currentThread().getId()