java - 升级到 springboot 2.4.13 后 RequestMappingInfo.getMatchingCondition 抛出 IllegalArgumentException

标签 java spring spring-boot spring-mvc

我有一段代码如下,

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。

最佳答案

SpringFramework issues 得到了解决方法.

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

requestMappingHandlerMapping.getUrlPathHelper().resolveAndCacheLookupPath(request);

关于java - 升级到 springboot 2.4.13 后 RequestMappingInfo.getMatchingCondition 抛出 IllegalArgumentException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70709043/

相关文章:

java - Android 像素完美对齐

java.lang.NoSuchMethodError : 'void org. thymeleaf.standard.processor.AbstractStandardExpressionAttributeTagProcessor

java - 将 DBRef 解析为 Json

java - 运行简单的 Camel ReSTLet 演示项目时遇到问题?

java - 将文件添加到可执行 jar 文件

带有 Redis 的 Spring HttpSession 不保存 SESSION cookie 值

java - 升级到 Java 7 后 Spring (3.2.0) ConfigurationClassEnhancer 中出现 Stackoverflow 错误

java - 模板设计模式的 Spring 配置问题

java - 未找到 JAX-RS 的处理程序方法

java - 无法使用@UpdateTimestamp注释更新时间戳