升级spring mvc 5.3后No more pattern data allowed after {*...} or ** pattern element错误解决
- 问题:今天把项目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>
<!-- 使用bean定义一个Interceptor,直接定义在mvc:interceptors根下面的Interceptor将拦截所有的请求 -->
<!--<bean class="com.platform.interceptor.LogInterceptor"/> -->
<mvc:interceptor>
<mvc:mapping path="/**" />
<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>
改之后:
<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>
正文到此结束