gpt4 book ai didi

java - Thymeleaf 3.0 Spring Boot + Security 集成不起作用

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:43:18 25 4
gpt4 key购买 nike

我努力让 Thymeleaf 在我基于 Spring Boot 1.4.3 的项目中与 Spring Security 一起工作。

例如标签

<div sec:authorize="hasAuthority('ADMIN')">

根本不被解析。

如果我尝试像这样手动添加 SpringSecurityDialect:

@Bean
public SpringSecurityDialect securityDialect() {
return new SpringSecurityDialect();
}

我得到:

Exception in thread "main" java.lang.NoClassDefFoundError: org/thymeleaf/dialect/IExpressionEnhancingDialect

我在我的依赖项中包含了以下内容:

<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity4</artifactId>
</dependency>

自动配置似乎没有添加SpringSecurityDialect

在我手动添加 Bean 后,出现上述异常。

这是一个错误还是我遗漏了什么?

我的 Thymeleaf 版本是:

<thymeleaf.version>3.0.2.RELEASE</thymeleaf.version>
<thymeleaf-extras-java8time.version>3.0.0.RELEASE</thymeleaf-extras-java8time.version>
<thymeleaf-layout-dialect.version>2.1.2</thymeleaf-layout-dialect.version>

最佳答案

要使其正常工作,如果您将 Thymeleaf 3.0.2 与 Spring Boot 1.4 一起使用,则需要强制使用 thymeleaf 的 3.0.1.RELEASE 版本-extras-springsecurity4(因为它继承了不能与 Thymeleaf 3 结合使用的版本 2.1.2):

<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity4</artifactId>
<version>3.0.1.RELEASE</version>
</dependency>

标签应该使用hasRole 函数。

<div sec:authorize="hasRole('ROLE_ADMIN')">

关于java - Thymeleaf 3.0 Spring Boot + Security 集成不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41388332/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com