Springboot 集成Spring Security教程 (一)
写在前面: 本文只做 Springboot 集成 security 的集成教程, 概念性的东西自行Google
官网: https://spring.io/projects/spring-security
创建Springboot项目
推荐使用 idea, 本文就是使用 idea 创建
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-quZo7B08-1609982223543)(https://ws4.sinaimg.cn/large/006tNc79ly1g1rmnplzobj312x0u00xr.jpg)]
依赖
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</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>
</dependencies>
数据库连接配置
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url = jdbc:mysql://localhost:3306/security
spring.datasource.username=root
spring.datasource.password=root
创建 index.html
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-uQaBUk3g-1609982223552)(https://ws4.sinaimg.cn/large/006tNc79ly1g1rn5g11gfj31ak0lowik.jpg)]
启动 Springboot 项目
自动跳转到登录页, 这是 security 默认登录页面, 输入默认用户名: user, 密码随机生成在控制台
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-sppYprvn-1609982223555)(https://ws2.sinaimg.cn/large/006tNc79ly1g1rn0tortlj318u0dun1n.jpg)]
登录成功后自动进入我们刚刚创建的 index 首页中, 表示我们的 Springboot 集成 Security 基础完成, 下一篇第二部分教程.