Spring Security的使用第一章 搭建环境及简单配置
Maven项目的Pom文件中添加maven依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
然后启动项目
启动项目可以看到登录的密码

Spring security默认自带首页,我们可以通过 user账号进行登录

如果需要自己定义登录的用户名和密码我们可以在配置文件中添加
spring:
security:
user:
name: root
password: root
此时我们新建一个请求接口
@RestController @Slf4j public class test { @GetMapping("/hello") public String hello(){ return "hello test"; } }
如果我们直接访问/hello则会跳转到登录界面,我们登录后就可以访问/hello了

浙公网安备 33010602011771号