记一次因升级springboot而触发的项目中隐藏的bug

5 篇文章 0 订阅
4 篇文章 0 订阅

记一次因升级springboot而触发的项目中隐藏的bug

springboot-1.3.5 --> spring-core-4.2.6.release
springboot-1.5.7 --> spring-core-4.3.11.release

问题描述

项目中有一个请求路径的映射末尾有一个空格,导致从springboot-1.3.5升级到1.5.7后,报404错误

示例代码

@RequestMapping(value="/query ",method=RequestMethod.GET)
public void query(){
    return null;
}

在query后多了个一个空格符

在原版本中,项目运行无误,但是升级后该路径就报404了

问题分析

经过一番debug,终于发现,是spring-core包中的一个类有了变化

AntPathMatcher

在该类的方法tokenizePath中发现了问题所在

 /**
  * Tokenize the given path pattern into parts, based on this matcher's settings.
  * <p>Performs caching based on {@link #setCachePatterns}, delegating to
  * {@link #tokenizePath(String)} for the actual tokenization algorithm.
  * @param pattern the pattern to tokenize
  * @return the tokenized pattern parts
  */

  protected String[] tokenizePattern(String pattern) {
         String[] tokenized = null;
         Boolean cachePatterns = this.cachePatterns;
         if (cachePatterns == null || cachePatterns.booleanValue()) {
                tokenized = this.tokenizedPatternCache.get(pattern);
         }
         if (tokenized == null) {
                tokenized = tokenizePath(pattern);
                if (cachePatterns == null && this.tokenizedPatternCache.size() >= 
CACHE_TURNOFF_THRESHOLD) {
                        // Try to adapt to the runtime situation that we're encountering:
                        // There are obviously too many different patterns coming in here...
                        // So let's turn off the cache since the patterns are unlikely to be reoccurring.
                       deactivatePatternCache();
                       return tokenized;
                }
                if (cachePatterns == null || cachePatterns.booleanValue()) {
                       this.tokenizedPatternCache.put(pattern, tokenized);
                }
         }
         return tokenized;
   }
   /**
   *Tokenize the given path String into parts, based on this matcher's 
settings.
   * @param path the path to tokenize
   * @return the tokenized path parts
   */
   protected String[] tokenizePath(String path) {
         return StringUtils.tokenizeToStringArray(path, this.pathSeparator, this.trimTokens, true);
   }

在方法tokenizePath中传递了一个属性trimTokens,这个属性在spring-core-4.2.6.release中是默认的true
在这里插入图片描述

而该属性在spring-core-4.3.11.release中是默认的false在这里插入图片描述

这就导致在执行org.springframework.util.StringUtils的tokenizeToStringArray方法时做了去空格的不同判断
在这里插入图片描述
具体这个属性的变化历史,我这里就没有去追究了,已经解决了我的疑惑咯

博客

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值