欢迎访问我的个人博客:guqing’s blog
首先检查你导入的SpringSecurity
版本
如果是五版本那么导入的thymeleaf的security扩展也要是五版本才能匹配,取不到值得原因是扩展版本不匹配
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity5</artifactId>
<version>3.0.4.RELEASE</version>
</dependency>
根据官方的说法;
This is a thymeleaf extras module, not a part of the Thymeleaf core (and as such following its own versioning schema), but fully supported by the Thymeleaf team.
This repository contains 3 projects:
thymeleaf-extras-springsecurity3 for integration with Spring Security 3.x
thymeleaf-extras-springsecurity4 for integration with Spring Security 4.x
thymeleaf-extras-springsecurity5 for integration with Spring Security 5.x
Current versions:
Version 3.0.4.RELEASE - for Thymeleaf 3.0 (requires Thymeleaf 3.0.10+)
Version 2.1.3.RELEASE - for Thymeleaf 2.1 (requires Thymeleaf 2.1.2+)
thymeleaf-extras-springsecurity3
版本只匹配Spring Security 3.x
同理4和5版本也是。
如果SpringBoot的版本是1.x,那么还需要注意使用spring boot的thymeleaf
启动器引入的thymeleaf
的版本也过低需要将版本升级一下。然后同上检查Security
的版本匹配就可以取到值了