Skip to content

Provide access to all configured interceptors in AbstractHandlerMapping #28985

Closed
@lizongbo

Description

@lizongbo

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。

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions