Spring Boot 集成 Spring Security

1、添加依赖

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-security</artifactId>
</dependency>

2、运行项目

会发现,访问时,弹出此页面

这是因为Spring Security对我们的工程默认使用”basic”身份认证,只要引入了Spring Security, 那么整个web应用都是安全的,所有资源访问都要经过身份验证授权才可以访问。

可用 user随机密码登录,随机密码可从web应用启动日志查询

扫描二维码关注公众号,回复: 2138223 查看本文章

当然也可以在application.properties里自定义username和password.

security.user.name=admin

security.user.password=123456

或者直接关闭这个默认的basic认证

security.basic.enabled=false

猜你喜欢

转载自www.cnblogs.com/amunamuna/p/9299709.html