创建springboot 项目,引入spring security坐标
java
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--spring security坐标-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
然后启动项目,访问任意一个controller的请求地址结果会跳转到一个登录界面:
java
@RestController
public class HelloController {
@RequestMapping("hello")
public String hello() {
return "hello spring security";
}
}
默认的用户名:user
默认的密码:在项目启动日志里面有一个 Using generated security password: c7006a0b-c0df-46ae-812c-2859d02492ac