【问题标题】:Spring Security Dialect sec:authorize not parsedSpring Security Dialect sec:authorize 未解析
【发布时间】:2019-04-14 14:09:45
【问题描述】:

我正在使用 spring boot 2.1.0 和 spring security 构建一个小应用程序。 我可以使用表单身份验证登录和退出。但是,sec:authorize 标记没有被解析或评估,呈现的 html 包含这些属性。

<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
    </dependency>
    <dependency>
        <groupId>org.thymeleaf.extras</groupId>
        <artifactId>thymeleaf-extras-springsecurity4</artifactId>
        <version>3.0.4.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>nz.net.ultraq.thymeleaf</groupId>
        <artifactId>thymeleaf-layout-dialect</artifactId>
        </dependency>

不知道我错过了什么

【问题讨论】:

标签: spring security spring-security thymeleaf dialect


【解决方案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>

另外,如果您使用的是 &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;,请不要将任何版本添加到您的 Thymeleaf Extras,让 Spring Boot 为您管理。

【讨论】:

  • 太棒了,谢谢 - 在配置中添加 springSecurityDialect 解决了问题
  • 很高兴我能帮上忙!如果你不介意也支持我的回答,那就太棒了?。
猜你喜欢
  • 2021-02-23
  • 2013-10-04
  • 2015-11-26
  • 2021-06-20
  • 2016-03-05
  • 2015-03-11
  • 1970-01-01
  • 2015-04-20
  • 2018-10-31
相关资源
最近更新 更多