在springboot中加入springsecurity的依赖
org.springframework.boot
spring-boot-starter-security
当引入这个依赖后,启动项目,springSecurity也会跟着启动,默认使用HttpBasic的方式启动,用户名是user,密码在启动日志里面,是个随机字符串。
文章图片
其中5ced945c-3f81-4e08-baab-0c02606971e1为登录密码。
有时候暂时不需要springSecurity服务时,例如直接访问一个接口,有登录拦截的话会访问不了,此时需要对springSecurty进行配置,放行所有的url。
配置如下:
package com.example.demo.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
/**
* @author shanpeng
*/
@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {
// 放行所有请求
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().anyRequest().permitAll();
}
}
【spring|springboot使springsecurity不用登录】完成配置后,实际效果上就是使springSecurity不生效。
推荐阅读
- Java|Java基础——数组
- 人工智能|干货!人体姿态估计与运动预测
- java简介|Java是什么(Java能用来干什么?)
- Java|规范的打印日志
- Linux|109 个实用 shell 脚本
- 程序员|【高级Java架构师系统学习】毕业一年萌新的Java大厂面经,最新整理
- Spring注解驱动第十讲--@Autowired使用
- =======j2ee|spring用注解实现注入的@resource,@autowired,@inject区别
- SqlServer|sql server的UPDLOCK、HOLDLOCK试验
- jvm|【JVM】JVM08(java内存模型解析[JMM])