将 Spring boot 版本从 2.1.6 迁移到 Spring boot 2.4 时出现以下错误

Dip*_*arg 17 java spring spring-boot

将我的项目从 Spring boot 版本 2.1.6 迁移到 2.4 时出现以下错误

{*...} 或 ** 模式元素后不允许再有模式数据

发生错误的代码片段

public class WebConfig implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(authInterceptor)
                .addPathPatterns("/**/test/**")
    }
}
Run Code Online (Sandbox Code Playgroud)

我知道 Spring boot 在 2.4 版本中禁用了 AntPathMatcher ,所以我也尝试了这个选项

Spring.mvc.pathpattern.matching-strategy= ant_path_matcher

但即使这样也行不通

任何帮助深表感谢

小智 17

使用 springdoc-openapi-ui 的最新版本 1.5.12,问题已解决。


小智 13

原因:错误是路径通配符问题。搜索发现spring升级到5.3后路径通配符发生了变化。官方的解释是“在Spring MVC中,之前是通过AntPathMatcher来分析路径的,但是从Spring 5.3.0开始改为使用WebFlux中引入的PathPatternParser”。

解决:具体解决方法是/**/*.css改为/*/*.css. 项目中可能涉及多个文件,必须进行更改。


小智 5

在你的 application.properties 中设置它。要么那样,要么只是编辑模式。

spring.mvc.pathmatch.matching-strategy=ant_path_matcher


Mar*_*ers 5

请注意,在较新版本的 Spring 中,正确的属性是spring.mvc.pathmatch.matching-strategy(而不是spring.mvc.pathpattern.matching-strategy

更多信息: https://docs.spring.io/spring-boot/docs/current/reference/html/application-properties.html#application-properties.web.spring.mvc.pathmatch.matching-strategy

相关问题:https://github.com/spring-projects/spring-boot/issues/28791