今天用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>