Java Thymeleaf不解释sec标记

Java Thymeleaf不解释sec标记,java,maven,spring-security,thymeleaf,Java,Maven,Spring Security,Thymeleaf,我遇到了一个问题,在我的spring boot项目中,thymleaf无法识别sec标记。e、 g.下面的sec:authentication未被保护,在浏览器的html中显示为原样 <!DOCTYPE html> <html xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/extras/spring-security"> <head th:replace="

我遇到了一个问题,在我的spring boot项目中,thymleaf无法识别sec标记。e、 g.下面的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>

org.thymeleaf.extras
thymeleaf-extras-springsecurity4
3.0.2.1发布

但还是没有运气。上述依赖关系似乎是大多数人的解决方案,你知道我还缺少什么吗?

可能有一些设置不正确。无论如何,这个问题总是可以通过添加缺少的依赖项或更改正在使用的依赖项来解决。因此,首先,尝试更改为
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>

org.thymeleaf.extras
thymeleaf-extras-springsecurity5
3.0.4.1发布

另外,如果您使用的是
spring boot starter父系统
,请不要向您的Thymeleaf Extras添加任何版本,让spring boot为您管理。

感谢升级到Thymeleaf-Extras-springsecurity5修复了它。很高兴我能提供帮助:)