前言
通过 SpringSecurity 学习专栏 中几篇文章的学习,我们 初识 了 SpringSecurity
,也分析了 SpringSecurity
的 启动流程。接下来我们就以典型的 RBAC模型
为例,来做一个实战项目
技术选型
截至到发文时,
SpringBoot
最新的GA
版本为2.7.2
SpringBoot
:2.7.2
SpringSecurity
:5.7.2
- 前端:
vue-element-admin
实战
1、创建项目
2、pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>boot-admin-example</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>boot-admin-example</name>
<description>boot-admin-example</description>
<properties>
<java.version>1.8</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</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>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
3、启动项目
得力于 SpringBoot
的强大特性,什么都不用配置就可以启动项目,访问 http://localhost:8080
,会跳转到默认的登录页面 /login
:
4、创建并启动前端项目
# 首先 cd 到存放项目的目录下,clone 项目到 vue-admin-example 目录
git clone https://github.com/PanJiaChen/vue-admin-template vue-admin-example
# 进入项目目录
cd vue-admin-example
# 安装依赖,使用淘宝镜像源加速
npm install --registry=https://registry.npm.taobao.org
# 本地开发 启动项目
npm run dev
总结
这篇文章我们只是创建好了前后端项目,在接下来的 SpringSecurity - 实战 RBAC(二) 文章中,我们会打通前后端项目,并且实现简单的登录功能。
代码已上传至 Gitee
中:
后端
:https://gitee.com/hoticket/boot-admin-example
前端
:https://gitee.com/hoticket/vue-admin-example.git