Springboot 集成Spring Security教程 (一)
写在前面: 本文只做 Springboot 集成 security 的集成教程, 概念性的东西自行Google
官网: https://spring.io/projects/spring-security
我的博客: http://www.izuul.com
创建Springboot项目
推荐使用 idea, 本文就是使用 idea 创建
依赖
<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
启动 Springboot 项目
自动跳转到登录页, 这是 security 默认登录页面, 输入默认用户名: user, 密码随机生成在控制台
登录成功后自动进入我们刚刚创建的 index 首页中, 表示我们的 Springboot 集成 Security 基础完成, 下一篇第二部分教程.