异常计算字符串数组的SpringEL表达式



在spring boot <= 2.4.3时,下面的代码段运行良好。

<div class="link-red ddmenu" th:with="urls=${new String[]{'/'}}"
th:classappend="${#arrays.contains(urls, #httpServletRequest.getRequestURI()) ? 'selected' : ''}">
<a href="/" th:href="@{/}"> <i class="fa fas fa-home"></i>Home
</a>
</div>

但是在升级到2.7.0之后,我得到这个解析异常。我该怎么做才能修好它?

Exception evaluating SpringEL expression: "new String[]{'/'}"

或者任何有关这个休息的信息,可以在任何thyymeleaf的官方网站上找到?

有趣的是,如果你继续往下看堆栈轨道,你会在底部发现这个错误:

Caused by: org.springframework.expression.spel.SpelEvaluationException: EL1005E: Type cannot be found 'String'

如果我把表达式改成:

th:with="urls=${new java.lang.String[]{'/'}}"

一切正常(用Spring Boot starter 2.6.7测试)。

最新更新