Spring Boot 2.6.7 URL 不区分大小写的配置

Spring Boot 2.6.7 URL case insensitive configuration

在 Spring Boot 2.6.7 中,我想将所有控制器的 URL 设置为不区分大小写。

我试过了,但没用

@Configuration
public class WebConfig extends WebMvcConfigurerAdapter {
    @Override
    public void configurePathMatch(PathMatchConfigurer configurer) {
        AntPathMatcher matcher = new AntPathMatcher();
        matcher.setCaseSensitive(false);
        configurer.setPathMatcher(matcher);
    }
}

我们可以通过application.properties文件配置吗?

根据文档 AntPathMatcher Documentation setCaseSensitive 的布尔值应该是 false 以获得不区分大小写的行为。

所以替换

matcher.setCaseSensitive(true);

matcher.setCaseSensitive(false);

在@Xiidref 解决方案之后你可以添加

spring.mvc.pathmatch.matching-strategy=ant_path_matcher

在您的 application.properties 文件中。