在Spring 3.2中禁用从路径变量修剪空格


问题内容

默认情况下,Spring从用作路径变量的字符串中修剪前导/尾随空格。我已经跟踪下来是因为 trimTokens 标志设置为 默认情况下
AntPathMatcher

不过,我不知道的是如何将该标志设置为 false

使用将其设置为 falseAntPathMatcher* 提供我自己的 RequestMappingHandlerMapping
bean 无效。
* __

如何使用JavaConfig更改此标志?

谢谢。


问题答案:

让您的配置扩展WebMvcConfigurationSupport覆盖requestMappingHandlerMapping()并相应地进行配置。

@Configuration
public MyConfig extends WebMvcConfigurationSupport {

    @Bean
    public PathMatcher pathMatcher() {
      // Your AntPathMatcher here.
    }

    @Bean
    public RequestMappingHandlerMapping requestMappingHandlerMapping() {
        RequestMappingHandlerMapping  rmhm = super.requestMappingHandlerMapping();
        rmhm.setPathMatcher(pathMatcher());
        return rmhm;
    }
}