spring升级后,useSuffixPatternMatch默认为false,导致test.do匹配不到test

问题:

spring升级后,发现useSuffixPatternMatch默认为false,导致test.do匹配不到test了

原因:

RequestMappingHandlerMapping.useSuffixPatternMatch(使用后缀模式匹配)在spring5.3版本以后已被默认关闭,使得"/test"不再匹配"/test.*"。

解决办法(已不建议使用):

转载于Turn off useSuffixPatternMatching by default · Issue #23915 · spring-projects/spring-framework (github.com),issue对修改原因也有描述。

代码进行web配置:

@Configuration
@EnableWebMvc
public class WebConfig implements WebMvcConfigurer {

    @Override
    public void configurePathMatch(PathMatchConfigurer configurer) {
        configurer
            // ...
            .setUseRegisteredSuffixPatternMatch(true);
    }
}

springmvc配置xml:

<mvc:annotation-driven>
    <mvc:path-matching suffix-pattern="true"/>
</mvc:annotation-driven>

吐槽:

这个其实是上家公司ssm老项目里常见的用法,用"test.do"去匹配"test"路径。然后我自己新建一个测试项目后,发现已经不生效了。搞半天,是原公司项目spring框架版本太老导致的。查网上也只有很老的中文教程,也不知道有没有升级版本的老哥踩到坑了。

posted @ 2022-10-26 23:09  二层楼  阅读(1411)  评论(0)    收藏  举报