您的位置:首页 > 汽车 > 新车 > SpringBoot开发——整合Spring Security

SpringBoot开发——整合Spring Security

2025/6/23 0:00:30 来源:https://blog.csdn.net/bjzhang75/article/details/142108851  浏览:    关键词:SpringBoot开发——整合Spring Security

文章目录

  • 一、快速上手Spring Security
    • 1、创建Maven工程 ,添加相关依赖
    • 2、创建Controller
    • 3、创建HTML
    • 4、创建application.yml
    • 5、启动项目,查看效果
    • 6、设置自定义密码
  • 二、权限管理
    • 7、创建SecurityConfig类
    • 8、修改Controller
    • 9、创建自定义登陆页面
    • 10、index.html
    • 11、admin.html
    • 12、效果

Spring Security是一个能够为基于Spring的企业应用系统提供声明式的安全访问控制解决方案的安全框架。它提供了一组可以在Spring应用上下文中配置的Bean,充分利用了Spring IoC,DI(控制反转Inversion of Control ,DI:Dependency Injection 依赖注入)和AOP(面向切面编程)功能,为应用系统提供声明式的安全访问控制功能,减少了为企业系统安全控制编写大量重复代码的工作。

一、快速上手Spring Security

1、创建Maven工程 ,添加相关依赖

创建Spring boot项目,添加Spring Security依赖和thymeleaf依赖:
添加依赖后,pom.xml文件内容如下:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>3.3.3</version><relativePath/> <!-- lookup parent from repository --></parent><groupId>com</groupId><artifactId>security</artifactId><version>0.0.1-SNAPSHOT</version><name>security</name><description>security</description><url/><licenses><license/></licenses><developers><developer/></developers><scm><connection/><developerConnection/><tag/><url/></scm><properties><java.version>22</java.version></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><!-- thymeleaf --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-thymeleaf</artifactId></dependency><!-- security --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-security</artifactId></dependency></dependencies><build><plugins>

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com