升级spring mvc 5.3后No more pattern data allowed after {*...} or ** pattern element错误解决

2021-01-05 09:52
300
0

问题:今天把项目spring版本升级到spring 5.3.2后,启动项目后初始化时报错,具体错误信息为:

“Caused by: org.springframework.web.util.pattern.PatternParseException: No more pattern data allowed after {*...} or ** pattern element”。

解决:

1、错误直观展示是路径统配问题,可是之前没有问题啊,后来经过一通查找发现是spring升级到5.3之后路径统配发生了变化,官方给出的解释是“In Spring MVC, the path was previously analyzed by AntPathMatcher, but it was changed to use PathPatternParser introduced in WebFlux from Spring 5.3.0.”。

原代码:

2、具体解决是把/**/*.html 改为 /*/*.html,项目中可能涉及多个文件,都要改。

修改后:

<mvc:interceptors>
  <mvc:interceptor>
   <mvc:mapping path="/*" />
   <mvc:exclude-mapping path="/js/*" />
   <mvc:exclude-mapping path="/statics/*" />
   <mvc:exclude-mapping path="/*/*.html" />
   <mvc:exclude-mapping path="/*/*.js" />
   <bean class="com.platform.interceptor.LogInterceptor" />
  </mvc:interceptor>
 </mvc:interceptors>

 

全部评论