关于spring boot url路径匹配斜杠“/”问题?

地址1:http://localhost:8762/hello
地址2:http://localhost:8762///hello

访问1 和访问2结果一样。

期望的是访问2返回404.

相关代码:

@RestController
public class HelloController {

    @GetMapping("hello")
    public String index() {
        return "Hello World";
    }

}
@SpringBootApplication
public class EurekaClientApplication extends WebMvcConfigurationSupport {

    public static void main(String[] args) {
        SpringApplication.run(EurekaClientApplication.class, args);
    }

    @Override
    protected void configurePathMatch(PathMatchConfigurer configurer) {
        configurer.setUseSuffixPatternMatch(false)
                .setUseTrailingSlashMatch(false);
    }
}
阅读 8.3k
1 个回答
新手上路,请多包涵

setUseTrailingSlashMatch(true);
设置为true为严格匹配。即可返回404

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题