See https://www.baeldung.com/spring-handler-mappings - explains BeanNameUrlHandlerMapping, SimpleUrlHandlerMapping
Debug DispatcherServlet - DispatcherServlet.getHandler
- this.handlerMappings - I have 5 incl. (each has a pathMatcher: AntPathMatcher https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/util/AntPathMatcher.html which has . match(String pattern, String path))
- RequestMappingHandlerMapping,
- mappingRegistry.urlLookup and .mappingLookup -> controller methods
- BeanNameUrlHandlerMapping,
- handlerMap (empty)
- SimpleUrlHandlerMapping,
- urlMap has the mappings for static resourced added via ResourceHandlerRegistry
- 2 EmptyHandlerMapping
- RequestMappingHandlerMapping,
Why is a mapping from URL -> controller missing? In org.springframework.web.servlet.handler.AbstractHandlerMethodMapping#initHandlerMethods see the detected beanNames (all beans) and the isHandler check a few lines down. -> detectHandlerMethods -> this.mappingRegistry.register
=> info or debug or trace logs on org.springframework.web.servlet.handler.AbstractHandlerMethodMapping
Upon request:
- org.springframework.web.servlet.DispatcherServlet#doService -> doDispatch calls getHandler, which looks into this.handlerMappings
- org.springframework.web.servlet.handler.AbstractHandlerMethodMapping#getHandlerMethods -> .MappingRegistry#getMappings -> this.mappingLookup
- org.springframework.web.servlet.handler.AbstractHandlerMethodMapping#getHandlerInternal
beanName requestMappingHandlerMapping sees only 39 beanNames => 12 in mappingLookup, 25 in urlLookup
Docs: beans defined in the parent context are accessible in the child contexts - but the mapping does not search the parent context by default
Why isn't a css/js/.. resource found?
(Presumably added via WebMvcConfigurationSupport.addResourceHandlers(ResourceHandlerRegistry)) => Is the mapping as expected in the mappingRegistry? (see the previous section) If it is:
Debug lookup in the SimpleUrlHandlerMapping- debug org.springframework.web.servlet.handler.AbstractUrlHandlerMapping#getHandlerInternal - see lookupPath, drill down to lookupHandler() - here it runs getPathMatcher().match(registeredPattern, urlPath) -> org.springframework.web.servlet.resource.ResourceHttpRequestHandler#handleRequest -> getResource() which tries to find the resource on the classpath / ... -> org.springframework.web.servlet.resource.PathResourceResolver#getResource(java.lang.String, java.util.List<? extends org.springframework.core.io.Resource>) NOTE: Inside org.springframework.web.servlet.handler.AbstractUrlHandlerMapping#lookupHandler look at the call to getPathMatcher().extractPathWithinPattern
lookupPath=/myapp/assets-verMS4wLjAtU05BUFNIT1Q=/myapp.css RESOURCE PATH=assets-verMS4wLjAtU05BUFNIT1Q=/myapp.css
AntPathMatcher.extractPathWithinPattern("/myapp/assets-ver{hash:.+?}/**/*", "/myapp/assets-verMS4wLjAtU05BUFNIT1Q=/myapp.css")
=> does stupid patternPart.indexOf('*') > -1 || patternPart.indexOf('?')
check