Mdc.clear () в зависимости не работает с перехватчикомJAVA

Программисты JAVA общаются здесь
Anonymous
Mdc.clear () в зависимости не работает с перехватчиком

Сообщение Anonymous »

У меня есть этот класс в моем приложении Spring Boot: < /p>

Код: Выделить всё

@Configuration
public class LogContextCleanerConfig {

@Bean
public LogContextCleaner logContextCleaner() {
return new LogContextCleaner();
}
}

< /code>
У меня также есть webconfig: < /p>
@Configuration
public class WebConfig implements WebMvcConfigurer {
@Autowired private LogContextCleaner logContextCleaner;

@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(loggingInterceptor(logContextCleaner);
}

private HandlerInterceptor loggingInterceptor(LogContextCleaner logContextCleaner) {
return new HandlerInterceptor() {
@Override
public void afterCompletion(HttpServletRequest req, HttpSerletResponse res, Object hander, Exception ex) throws Exception {
logContextCleaner.afterCompletion(req, res, handler, ex);
}
};
}
}
< /code>
Последствия находятся в зависимости и выглядит следующим образом: < /p>
@Component
public class LogContextCleaner implements HandlerInterceptor {
@Override
public void afterCompletion(HttpServletRequest req, HttpServletResponse res, Object handler, Exception ex) throws Exception {
MDC.clear();
}
mdc.clear () , кажется, никогда не выполняется. Я не могу понять, почему. Любые указатели будут высоко оценены.


Подробнее здесь: https://stackoverflow.com/questions/797 ... nterceptor

Вернуться в «JAVA»