我有一个带有此pom.xml的SpringBoot应用程序:
...
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.6.RELEASE</version>
<relativePath/>
</parent>
<!-- Spring Security -->
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity4</artifactId>
</dependency>
...
,它工作正常。 然后,我将SpringBoot版本更新为
...
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.0.RELEASE</version>
<relativePath/>
</parent>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity4</artifactId>
<version>3.0.4.RELEASE</version>
</dependency>
...
我在1个模板中遇到此错误:
Exception evaluating SpringEL expression: "#authorization.expression('hasRole(''ROLE_ADMIN'')')" (template: "tdk/common/menu" - line 87, col 21)
此处是模板:
<li th:if="${#authorization.expression('hasRole(''ROLE_ADMIN'')')}" class="menu-principal pure-menu-item" th:classappend="${activeMenuItem == ‘tdkMessages'} ? pure-menu-selected">
<a href=“/tdk/list" class="pure-menu-link">
<i class="fas fa-cloud-download-alt fa-lg fa-fw"></i> tdk
</a>
</li>
答案 0 :(得分:3)
Thymeleaf现在具有针对Spring Security 5的特殊扩展名/方言。您将需要使用它而不是Spring Security 4的扩展名/方言。
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity5</artifactId>
</dependency>
应该做到这一点,<version>
由Spring Boot管理,因此您不需要添加它。