Skip to content

Provide better lifecyle for WebMvcConfigurer.configurePathMatch #26427

@philwebb

Description

@philwebb

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?

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