SpringBoot 和 SpringMvc 的路径匹配问题
SpringMvc访问/test和/test.**时会使用/test接口SpringBoot访问/test和/test.**时,只有/test会使用/test接口
原因:
1、观察RequestMappingHandlerMapping的源码,可以看到SpringMVC底层默认会开启/test或/test.**访问
/test接口的规则。

这里的useSuffixPatternMatch默认会置为 true

所以当访问/test或/test.**时会调用/test接口。
2、观察SpringBoot的RequestMappingHandlerMapping的源码,可以发现SpringBoot的认证规则和 SpringMVC一致。但SpringBoot的 EnableWebMvcConfiguration的configurePathMatch方法修改了 useSuffixPattern的默认值。

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

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


浙公网安备 33010602011771号