Closed
Description
Versions
Spring Version 5.3.22
Overview
I wanted to get all the HandlerInterceptor that had been registered in Spring MVC after the application was successfully launched, but I found that this method was protected, so it could not be obtained directly, and I had to use the reflection method to call, so it was recommended to set it to a public method.
My code was:
RequestMappingHandlerMapping requestMappingHandlerMapping = configurableApplicationContext.getBean(RequestMappingHandlerMapping.class);
Field adaptedInterceptorsField = ReflectionUtils.findField(RequestMappingHandlerMapping.class, "adaptedInterceptors");
adaptedInterceptorsField.setAccessible(true);
List<HandlerInterceptor> hiList = (List<HandlerInterceptor>) adaptedInterceptorsField.get(requestMappingHandlerMapping);
I also suggest that Springboot's actuator provide endpoints to get that information。