其实很多小白和搞不懂springboot3.0以上版本对应的security版本是多少也包括本菜鸟,今天做了项目才知道,版本不匹配是效果没有体现出来的,就比如,我现在使用springboot和security来进行前端鉴权,但是由于文档是springboot是二点几以上的,而现在已经是3.0以上了,所以当时直接没有成功的效果,一直网上找,才知道了现在版本和以前不一样,直接把依赖改了就行,这个图就是springboot3版本对应的
添加对应的依赖 <!-- spring-security --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency> <!-- thymeleaf整合spring-security --> <dependency> <groupId>org.thymeleaf.extras</groupId> <artifactId>thymeleaf-extras-springsecurity6</artifactId> </dependency>
别忘了html页面也要添加
<html xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/extras/spring-security">
最后就可以在相应的地方进行鉴权了
sec:authorize="hasAnyAuthority('/admin/all')"