Add support for detecting only local beans for DispatcherServlet #35738
      
        
          +112
        
        
          −20
        
        
          
        
      
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
The goal of this PR is to be able to configure the
DispatcherServletto 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:handlerAdaptershandlerExceptionResolversviewResolversThe 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 theAntPathMatcherto block access to**/actuator/*. However, theAntPathMatcherwill no longer be there in Spring 7 and I wanted to find a better solution.I did manage to find
WebMvcEndpointChildContextConfigurationfrom Spring Boot, that is achieving exactly what we are looking for. However, I wanted to see if we can avoid the need of all thoseCompositeHandlerMapping,CompositeHandlerAdapter, etc. and let theDispatcherServletitself handle this.If this gets accepted then the different composites in Spring Boot can be removed, and the Actuator management
DispatcherServletwould only need to changeto something like
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