[英]Spring Security - Thymeleaf - Can I evaluate SPEL Expressions inside sec:authorize tags?
[英]Thymeleaf not interpreting sec tags
我遇到了一個問題,在我的spring boot項目中,thymleaf無法識別sec標簽。 例如,下面的sec:authentication未被解釋,並顯示在瀏覽器的html中
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
xmlns:sec="http://www.thymeleaf.org/extras/spring-security">
<head th:replace="fragments/header"> </head>
<body>
<div id="container">
Roles <span sec:authentication="principal.authorities"></span>
</div>
<footer>
<div th:replace="fragments/footer"></div>
</footer>
</body>
</html>
通過閱讀,我需要以下依賴項,已將其添加到我的項目中。
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity4</artifactId>
<version>3.0.2.RELEASE</version>
</dependency>
但是仍然沒有運氣。 上面的依賴性似乎是大多數人的解決方案,還有什么想法我可能會錯過的嗎?
可能有些事情可能設置不正確。 無論如何,通過添加缺少的依賴項或更改所使用的依賴項,往往可以始終解決此問題。 因此,首先,嘗試更改為springsecurity5
。 並添加以下@Bean
。
組態
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.thymeleaf.extras.springsecurity5.dialect.SpringSecurityDialect;
@Configuration
public class LeafConfig {
@Bean
public SpringSecurityDialect springSecurityDialect(){
return new SpringSecurityDialect();
}
}
POM
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity5</artifactId>
<version>3.0.4.RELEASE</version>
</dependency>
另外,如果您使用的是<artifactId>spring-boot-starter-parent</artifactId>
,請不要在Thymeleaf Extras中添加任何版本,讓Spring Boot為您管理。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.