我正在开发一个简单的项目来实现 Spring 安全。 当我尝试使用 Spring 和 Thymeleaf 的 Logout 链接时,问题就出现了。
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>
导航栏.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>
最佳答案
当 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>
关于java - 如何解决这个: Exception evaluating SpringEL expression: "#authorization.expression(' isAuthenticated( )')"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52761395/