Currently WebMvcConfigurer.configurePathMatch(...) is called as a side-effect of WebMvcConfigurationSupport.getPathMatchConfigurer(). This makes it quite hard to use in @Bean method since it's hard to tell if the @Bean method or the configurePathMatch(...) method will be called first.
You can see an example of this in Spring Data Rest where the restHandlerMapping bean would ideally have a PatternParser on the delegates before the afterPropertiesSet() method is called. The current solution of overriding configurePathMatch and calling setPatternParser directly is brittle because the parser is needed before afterPropertiesSet() is called. This leads to issues such as #26415
It's possible to work-around the issue by adding @DependsOn("mvcPathMatcher") which will indirectly trigger the WebMvcConfigurationSupport.getPathMatchConfigurer() method, but this isn't ideal.
I wonder if we could make PathMatchConfigurer or the PatternParser a @Bean so that it can be injected directly if it's needed?
Currently
WebMvcConfigurer.configurePathMatch(...)is called as a side-effect ofWebMvcConfigurationSupport.getPathMatchConfigurer(). This makes it quite hard to use in@Beanmethod since it's hard to tell if the@Beanmethod or theconfigurePathMatch(...)method will be called first.You can see an example of this in Spring Data Rest where the restHandlerMapping bean would ideally have a
PatternParseron the delegates before theafterPropertiesSet()method is called. The current solution of overridingconfigurePathMatchand callingsetPatternParserdirectly is brittle because the parser is needed beforeafterPropertiesSet()is called. This leads to issues such as #26415It's possible to work-around the issue by adding
@DependsOn("mvcPathMatcher")which will indirectly trigger theWebMvcConfigurationSupport.getPathMatchConfigurer()method, but this isn't ideal.I wonder if we could make
PathMatchConfigureror thePatternParsera@Beanso that it can be injected directly if it's needed?