SpringBoot 和 SpringMvc 的路径匹配问题

  • SpringMvc 访问 /test/test.**时会使用/test接口
  • SpringBoot 访问 /test/test.**时,只有 /test会使用/test接口

原因:

1、观察RequestMappingHandlerMapping的源码,可以看到SpringMVC底层默认会开启/test/test.**访问

/test接口的规则。

20200911221453722

这里的useSuffixPatternMatch默认会置为 true

1991137

所以当访问/test/test.**时会调用/test接口。

2、观察SpringBootRequestMappingHandlerMapping的源码,可以发现SpringBoot的认证规则和 SpringMVC一致。但SpringBootEnableWebMvcConfigurationconfigurePathMatch方法修改了 useSuffixPattern的默认值。

20200911221517604

点击 isUseSuffixPattern方法,会返回一个默认的 useSuffixPattern

20200911221529593

点击这个 useSuffixPattern,会看到它的值为 false,即SpringBoot关闭了SpringMVC默认的匹配规则

20200911221539605

原文地址:https://www.cnblogs.com/xlwq/p/13654749.html