springboot集成security需要三步:
一、引入依赖
<!--集成安全框架-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
</dependency>
<!--thymeleaf整合security:依赖,旧版springboot不支持5版本,使用4版本集成安全框架-->
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity5</artifactId>
<version>3.0.4.RELEASE</version>
</dependency>
二、WebSecurityConfigurerAdapter抽象类得子类实现

具体实现类
package com.offcn.pj.controller.page.config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.Web

本文介绍了如何在Spring Boot项目中集成Spring Security,包括引入依赖、实现WebSecurityConfigurerAdapter和UserDetailsService接口,以及解决集成过程中遇到的同源策略限制、安全拦截、静态资源访问和栈溢出异常等问题。
最低0.47元/天 解锁文章
363

被折叠的 条评论
为什么被折叠?



