你这应该是老版本的SpringBoot了,首先你要知道SpringBoot是基于Spring的。
版本对应如下表:序号SpringBootSpringframework12.45.3
22.35.2
32.25.2
42.15.1
52.05
下面说一下你这个问题,这个特性叫做后缀匹配 SuffixMatch
在老版本中,这个特性是用来识别资源类型的,比如你问题描述中,虽然代码写的是@GetMapping("/abc"),但因为后缀匹配,实际上可以匹配"abc.html","abc.pdf","abc.json"等等,这个特性在以前是很有帮助的,但是现在浏览器可以使用"Accept" head头来指明资源类型,也就不需要SpringFramework再"多此一举"了,而且因为这个特性的存在,很多人认为是个bug,纷纷给Spring提了很多 issue
所以,从Spring5.3开始,这个特性就默认关闭了,所以如果你使用的是目前最新的SpringBoot2.4,就不会遇到这个问题。
当然,既然你碰到了,想要在老版本中关闭,官方也提供了关闭办法,原文如下:To completely disable the use of path extensions in versions prior to 5.3, set the following:useSuffixPatternMatching(false), see PathMatchConfigurer
favorPathExtension(false), see ContentNegotiationConfigurer
既然都说到了这里,就顺便把配置类也一块给你贴上吧:@Configuration
public class WebMvcConfig extends WebMvcConfigurerAdapter {
@Override
public void configurePathMatch(PathMatchConfigurer configurer) {
configurer.setUseSuffixPatternMatch(false);
}
@Override
public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
configurer.favorPathExtension(false);
}
}
自己粘贴到代码里试试吧,有问题欢迎私信我