Skip to content

Conversation

@filiphr
Copy link
Contributor

@filiphr filiphr commented Nov 1, 2025

The goal of this PR is to be able to configure the DispatcherServlet to only look for beans in the local application context, i.e. do not look in all ancestors.

The PR is currently only doing this for the HandlerMapping(s). However, if this is something that is acceptable for the Spring Team then I can adjust the rest of the beans in the dispatcher servlet:

  • handlerAdapters
  • handlerExceptionResolvers
  • viewResolvers

The reason for this is that we are using different DispatcherServlet(s) to expose different REST APIs and with Spring Boot Actuator the actuator endpoints were being exposed in our servlets as well. We have remedied that using Spring Security and the AntPathMatcher to block access to **/actuator/*. However, the AntPathMatcher will no longer be there in Spring 7 and I wanted to find a better solution.

I did manage to find WebMvcEndpointChildContextConfiguration from Spring Boot, that is achieving exactly what we are looking for. However, I wanted to see if we can avoid the need of all those CompositeHandlerMapping, CompositeHandlerAdapter, etc. and let the DispatcherServlet itself handle this.

If this gets accepted then the different composites in Spring Boot can be removed, and the Actuator management DispatcherServlet would only need to change

dispatcherServlet.setDetectAllHandlerAdapters(false);
dispatcherServlet.setDetectAllHandlerExceptionResolvers(false);
dispatcherServlet.setDetectAllHandlerMappings(false);
dispatcherServlet.setDetectAllViewResolvers(false);

to something like

dispatcherServlet.detectLocalHandlerMappingsOnly()
dispatcherServlet.detectLocalHandlerExceptionResolversOnly();
dispatcherServlet.detectLocalHandlerMappingsOnly();
dispatcherServlet.detectLocalViewResolversOnly();

I'm also open to adjusting the naming of the methods as well. It does not have to be exactly like I've done in this PR.

Thanks for taking the time and considering this PR

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Nov 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: waiting-for-triage An issue we've not yet triaged or decided on

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants