pom文件
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.4.1</version>
</dependency>
启动类
@RestController
@SpringBootApplication
public class SecurityApplication {
@RequestMapping("/")
public String hello() {
return "hello";
}
public static void main(String[] args) {
SpringApplication.run(SecurityApplication.class, args);
}
}
启动springboot后控制台输出一行密码
访问 localhost:8080,出现登录界面
分别填入user和控制台中打印出的密码,再点击登录