如何解决这个问题:评估SpringEL表达式的异常:“#authorization.expression('isAuthenticated()')”?

时间:2018-10-11 13:33:03

标签: java class spring-boot exception

我正在研究简单的项目 春季安全性。 当我尝试使用 Spring Thymeleaf 的注销链接工作时,问题就来了。

1.pom.xml

    <!--Spring Boot Dependencies  - Security -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
    </dependency>

    <!-- Dependencies Spring Security-->
    <dependency>
        <groupId>org.thymeleaf.extras</groupId>
        <artifactId>thymeleaf-extras-springsecurity4</artifactId>
        <version>2.1.2.RELEASE</version>
        <scope>compile</scope>
    </dependency>

navbar.html

<ul class="nav navbar-nav navbar-right">
                <!--<li><a th:href="@{/login}" th:text="#{navbar.login.text}"></a></li>-->
                <li th:if="${#authorization.expression('isAuthenticated()')}">
                    <a th:href="@{/login}" th:text="#{navbar.login.text}"/>
                </li>
                <li th:if="${#authorization.expression('isAuthenticated()')}">
                    <form id="f" th:action="@{/logout}" method="post" role="form" class="navbar-form">
                        <button type="submit" th:text="#{navbar.logout.text}" class="btn btn-primary"/>
                    </form>
                </li>
            </ul>

错误提示: enter image description here

1 个答案:

答案 0 :(得分:2)

当Thymeleaf Extras Spring Security版本与Spring Framework版本不兼容时,会发生此错误,在这种情况下,Spring Boot版本与Spring Framework版本5.x兼容,而Thymeleaf Extras Spring Security版本为4 。X。您需要在pom.xml中更新artifactId,然后选择兼容的版本或让Spring Boot为您选择版本

<dependency>
    <groupId>org.thymeleaf.extras</groupId>
    <artifactId>thymeleaf-extras-springsecurity5</artifactId>
    <scope>compile</scope>
</dependency>