解决Spring Boot Security – Thymeleaf sec:authorize 标签不生效

今天用Spring Boot 2.1.3 + Spring Security + Thymeleaf 测试一个登录的权限控制 Demo

发现使用 

sec:authorize
sec:authentication

这两个标签不生效

下面来说一下解决方案:

1、SpringBoot 工程默认自动导入的包版本不兼容

在pom文件中导入对应的包

<!--springsecurity4 要指定3.0以上版本,否则权限标签可能无法工作-->
<dependency>
    <groupId>org.thymeleaf.extras</groupId>
    <artifactId>thymeleaf-extras-springsecurity4</artifactId>
    <version>3.0.4.RELEASE</version>
</dependency>

2、页面<html> 标签中导入对应的命名空间

<html xmlns:th="http://www.thymeleaf.org"
	  xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity4">

3、SpringBoot 版本问题

由于测试时发现SpringBoot版本2.1.3的标签失效

百度了一下这个问题

需要把SpringBoot 的版本调整到 2.1.X 以下

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.8.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

 

评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值