此博客是记录自己学习过程的记录
第一个SpringSecurity项目
导入依赖
详细的步骤我就不多说了,使用IDEA创建过SpringBoot项目的人一般都能看懂。
这一步我们可以在使用IDEA创建SpringBoot项目的时候完成,如下图:
在创建SpringBoot项目时,勾选Spring Security即导入SpringSecurity的依赖。
测试
创建一个测试类来进行我们SpringSecurity的第一次测试,如下:
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/test")
public class TestController {
@GetMapping("/hello")
public String hello(){
return "hello security";
}
}
启动项目,输入网址,然后我们发现网页跳转到了一个登陆页面,如下图:
这就是SpringSecurity的认证页面,用户名默认为user,而密码在项目启动时已经打印在编译器的控制台了,如下图:
当我们用户名和密码都输入正确之后,我们将会跳转到我们原本访问的页面当中,如下图: