springboot 集成Spring Security

创建springboot工程

https://www.malaoshi.top/show_1EF5qXjMmlZR.html
https://www.malaoshi.top/show_1EF25CKZ1Qx8.html
https://www.malaoshi.top/show_1EF5qXhI66uM.html

修改pom.xml

添加下面依赖

<!-- 添加security依赖 -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-security</artifactId>
</dependency>

创建首页

创建 index.html,目录结构:

启动服务

启动服务时,会显示随机生成的登录密码,用户名是:user

测试

访问 http://localhost:8080/ ,访问结果如下:

不论访问什么url,都被security拦截,跳转到内置的登录页

登录

用户名:user
密码:启动服务时打印的密码

登录成功后,默认重定向到 http://localhost:8080/ ,即:默认访问上面创建的 index.html


原文出处:/show_1EF5zPFZmedu.html