【问题标题】:RequestMappingInfo.getMatchingCondition throwing IllegalArgumentException after upgrading to springboot 2.4.13升级到springboot 2.4.13后RequestMappingInfo.getMatchingCondition抛出IllegalArgumentException
【发布时间】:2022-01-14 10:18:44
【问题描述】:

我有一段代码如下,

final Entry<RequestMappingInfo, HandlerMethod> e = mappingHandler.getHandlerMethods()
        .entrySet()
        .stream()
        .filter(entry -> entry.getKey().getMatchingCondition(request) != null)
        .findFirst()
        .orElse(null);

在 spring-boot 版本 2.3.8.RELEASE 中运行良好,但如果我将其升级到 2.4.13,它会引发如下异常,

java.lang.IllegalArgumentException: Expected lookupPath in request attribute "org.springframework.web.util.UrlPathHelper.PATH".
at org.springframework.util.Assert.notNull(Assert.java:201)
at org.springframework.web.util.UrlPathHelper.getResolvedLookupPath(UrlPathHelper.java:213)
at org.springframework.web.servlet.mvc.condition.PatternsRequestCondition.getMatchingCondition(PatternsRequestCondition.java:280)
at org.springframework.web.servlet.mvc.method.RequestMappingInfo.getMatchingCondition(RequestMappingInfo.java:406)

我尝试在网上查找并找到https://github.com/spring-projects/spring-framework/issues/27715,但我无法联系起来,因为该问题说明了有关自己构建映射的内容,而我根本没有这样做。我正在使用命中上述代码的 MockMvc 对象调用 Rest Endpoint。

【问题讨论】:

    标签: java spring spring-boot spring-mvc


    【解决方案1】:

    SpringFramework issues 获得了解决方法。

    但是,我在 RequestMappingInfo 中使用了较旧的路径/请求匹配机制,并且在 Filter 中使用了 RequestMappingHandlerMapping,特别是 OncePerRequestFilter。 PATH 等某些属性稍后在代码中设置,因此会出现错误。尽管根据社区线程,在 OncePerRequestFilter 中使用 RequestMappingHandlerMapping (我上面的方式)是不好的做法,调用下面的代码明确地为我解决了这个问题,

    requestMappingHandlerMapping.getUrlPathHelper().resolveAndCacheLookupPath(request);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-08-22
      • 2014-07-02
      • 2016-04-30
      • 1970-01-01
      • 2013-05-25
      • 2017-10-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多