我遇到了一个问题,thymleaf 无法识别我的 Spring Boot 项目中的 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 为您管理。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)