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
但即使这样也行不通
任何帮助深表感谢
小智 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
请注意,在较新版本的 Spring 中,正确的属性是spring.mvc.pathmatch.matching-strategy(而不是spring.mvc.pathpattern.matching-strategy)
相关问题:https://github.com/spring-projects/spring-boot/issues/28791
| 归档时间: |
|
| 查看次数: |
30367 次 |
| 最近记录: |