克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
AGPL-3.0

后台权限管理系统jee-fast

jee-fast是基于SpringBoot、Vue.js、Element UI等主流前后端技术,采用前后端分离架构实现的后台权限管理系统,也是一款界面优雅、架构优良、代码简洁、功能完善的快速开发平台。

项目基于:书籍《Spring Boot + Spring Cloud + Vue + Element项目实战手把手教你开发权限管理系统》

1 功能介绍

  • 系统登录:用户登录、token认证
  • 系统管理:用户管理、机构管理、角色管理、菜单管理、字典管理、配置管理
  • 日志管理:登录日志、操作日志
  • 监控管理:在线用户、数据监控
  • 开发文档
  • 备份还原
  • 主题切换
  • 微服务:注册中心Consul,服务监控SpringBoot Admin,服务调用Ribbon、Fegin,服务熔断Hystrix、Turbine,服务网关SpringCloud Zuul,链路追踪Sleuth、ZipKin,配置中心Cloud Config、Bus

2 系统架构

2.1 前端架构

前端架构
核心框架使用Vue.js,UI使用Element,前后端交互使用axios,模拟接口数据使用mock

2.2 后端架构

后端架构
主题架构使用Spring Boot、Spring Security、Spring Cloud、Mybatis
注册中心为Consul
构建工具为Maven
数据库为MySQL

3 项目展示

1.登录界面
登录界面

2.系统主页
系统主页

3.用户管理
用户管理

4.机构管理
机构管理

5.角色管理
角色管理

6.菜单管理
菜单管理

7.用户个人中心
用户个人中心

4 前端项目介绍

4.1 技术选型

  1. 前端框架:Vue 2.x
  2. 页面组件:Element 2.x
  3. 状态管理:Vuex 2.x
  4. 后台交互 axios 0.18.x
  5. 图标:Font Awesome 4.x

4.2 开发环境

  1. Visual Studio Code 提供浏览器下载太慢,可以将下载链接前面的https://az764295.vo.msecnd.net/换为http://vscode.cdn.azure.cn/

  2. Node JS Node JS提供的NPM依赖管理和编译打包工具使用非常方便,要是用NPM就需要安装NodeJS。

  • 安装打包工具webpack npm install webpack -g

  • 安装vue脚手架项目初始化工具vue-cli npm install vue-cli -g

  • 配置淘宝镜像 npm install -g cnpm --registry=https://registry.npm.taobao.org 安装成功后用cnpm代替npm命令即可。

  • 安装node.js包管理器Yarn npm install yarn -g
    切换为淘宝镜像:
    yarn config set registry https://registry.npm.taobao.org

NPM与Yarn命令关系:

NPM Yarn
npm install yarn install
npm install --save [package] yarn add [package]
npm install --save-dev [package] yarn add [package] --dev
npm install --global [package] yarn global add [package]
npm uninstall --save [package] yarn remove [package]
npm uninstall --save-dev [package] yarn remove [package]

4.3 项目结构

jee-fast-ui  
  -- build:项目编译模块  
  -- config:项目配置模块  
  -- src:项目源码模块  
    -- assets: 静态资源,图标、字体、国际化信息  
	-- components: 组件库,封装常用组件  
	-- http:后台交互模块,统一后台接口请求API  
	-- i18n:国际化模块,使用Vue i18  
	-- mock:Mock模块,模拟接口调用并返回定制数据
	-- permission:权限控制模块,处理权限认证逻辑  
	-- router:路由管理模块,负责页面路由配置  
	-- store:状态管理模块,提供组件之间状态共享  
	-- utils:工具模块,提供通用的工具方法  
	-- views:页面模块,各种页面视图组件  

4.4 项目部署

  1. 下载源码
  2. 编译源码
    在项目目录下打开cmd终端,执行npm install命令,下载依赖包。
  3. 本地运行项目
    执行npm run dev命令启动项目,启动后通过http://localhost:8080访问项目。
  4. 服务器运行项目
    执行npm run build命令,进行打包,打包后会生成dist目录。将dist目录直接放到web服务器(如Tomcat),启动服务器即可访问。
  5. Mock开关
    修改src/mock/index.js中的openMock变量开启或关闭Mock功能。开启Mock功能可以模拟大部分后台接口数据。
  6. 修改配置
    自定义端口修改config/index.js下的port属性。后台接口和备份服务器地址配置在src/utils/global.js

5 后端项目介绍

5.1 开发环境

  1. 运行环境:JDK1.8+

  2. 开发工具:Eclipse

  3. 数据库: MySQL

  4. 构建工具:Maven
    JDK、Ecplise、MySQL、Maven自行安装

  5. 注册中心:consul
    本系统采用Consul作为注册中心,Consul服务端需要独立安装,进入官网下载后解压,进入Consul目录,cmd执行consul agent -dev启动服务。
    -dev表示开发模式运行,-server表示服务模式运行。
    启动成功后访问http://localhost:8500进入Consul服务管理界面。

  6. 链路追踪:zipkin
    Spring Cloud 2.0以后官方不支持自建Server了,改成提供编译好的jar包供用户使用。
    (1)方法一:Java环境运行jar包
    zipkin官网下载jar包后执行
    java -jar zipkin-server-2.23.2-exec.jar --STORAGE_TYPE=elasticsearch --ES_HOSTS=127.0.0.1:9200
    使用elasticsearch存储方式,需要先安装并运行elasticsearch。
    如果想简单通过内存方式启动:
    java -jar zipkin-server-2.23.2-exec.jar

(2)方法二:Docker部署
首先需要安装好Docker环境。
使用elasticsearch存储方式,先拉取ZipKin和Elasticsearch镜像

docker pull openzipkin/zipkin
docker pull docker.elastic.co/elasticsearch/elasticsearch:6.3.0

创建文件夹结构:

dockerfile
	|- elasticsearch
	|	|- data
	|- docker-compose.yml

创建模板文件docker-compose.yml,放在jee-fast-zipkin下:

version: '3'
services:
  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.11.1
    container_name: elasticsearch
    restart: always
    networks:
      - elk
    ports:
      - 9200:9200
    volumes:
      - ./elasticsearch/data:/usr/share/elasticsearch/data
    environment:
      - discovery.type=single-node
  zipkin:
    image: openzipkin/zipkin
    container_name: zipkin
    restart: always
    networks:
      - elk
    ports:
      - 9411:9411
    environment:
      - STORAGE_TYPE=elasticsearch
      - ES_HOSTS=elasticsearch
networks:
  elk:

进入dockerfile目录,启动服务:docker-compose up -d
如果想简单内存方式启动,只启动一个ZipKin容器即可:docker run -d -p 9411:9411 openzipkin/zipkin
通过docker ps目录查看进程。
访问http://127.0.0.1:9411查看zipkin界面。

  1. 消息队列RabbitMQ
    配置中心客户端需要使用到消息总线Spring Cloud Bus刷新配置,消息总线需要依赖RabbitMQ消息服务,所以如果需要配置中心服务,需先安装RabbitMQ。 安装RabbitMQ:
    直接下载安装包安装或者使用docker安装:
# 拉取镜像
docker pull rabbitmq:management
# 查看镜像列表
docker images
# 创建容器
docker run -d --name rabbitmq -p 5671:5671 -p 5672:5672 -p 4369:4369
  -p 25672:25672 -p 15671:15671 -p 15672:15672 rabbitmq:management
# 查看启动容器
docker ps

访问Web管理界面:http://IP:15672,系统默认账号:guest/guest

5.2 技术选型

  1. 核心结技术:Spring Boot 2.x
  2. 安全框架:Spring Security 5.x
  3. 持久层框架:MyBatis 3.x
  4. 数据库连接池:Druid 1.x
  5. 日志管理:slf4j、log4j
  6. 消息对列:RabbitMQ
  7. 接口文档:Swagger 2.9.x

5.3 项目结构

jee-fast:聚合模块,一键执行打包所有模块  
jee-fast-common:公共代码模块,主要放置一些工具类  
jee-fast-core:核心业务代码模块,主要封装公共业务模块  
jee-fast-admin:后台管理模块,包含用户、角色、菜单等  
jee-fast-backup:系统数据备份模块  
jee-fast-monitor:系统监控模块,监控应用  
jee-fast-producer:服务提供者,测试模块1  
jee-fast-producer2:服务提供者,测试模块2  
jee-fast-consumer:服务消费者,测试模块  
jee-fast-hystrix:熔断监控模块,实时监控Hystrix  
jee-fast-zuul:服务网关模块,实现服务路由,外部调用微服务

5.4 项目部署

  1. 下载源码
  2. 编译源码
    在fast-pom工程下执行maven clean install命令下载依赖。
  3. 导入数据库
    使用doc/sql下的数据库脚本jee-fast.sql,初始化数据库。同时修改fast-admin等工程下的application.yml文件中的数据源等配置信息。
  4. 本地运行项目
    项目具体启动方式如下:
  • 基础服务
    (1)注册中心Consul,基础服务
    在consul安装目录下cmd执行consul agent -dev启动服务,启动成功后访问http://localhost:8500进入Consul服务管理界面。
    (2)系统服务监控jee-fast-monitor,执行JeeFastMonitorApplication,启动监控服务。
    启动成功后访问http://localhost:8000进入服务监控界面,wallboard页面显示当前监控的应用,单击应用进入应用监控详情页面,查看各种应用监控信息,比如应用环境、处理器消息、线程信息、类加载、堆栈使用和垃圾回收情况等。
    Linux服务器

  • 权限管理模块
    (1)系统数据备份模块jee-fast-backup,执行JeeFastBackupApplication启动服务。
    (2)管理后台模块jee-fast-admin,执行JeeFastAdminApplication启动服务。

  • 其他微服务模块
    执行JeeFast**Application启动服务,注意一些模块需要启动对应软件服务。

  1. 服务器运行项目
    执行maven clean package命令进行打包,将打包后的jar文件上传服务器,执行命令运行相应模块:
    nohup java -jar xxx.jar >run.log 2>&1 &

5.5 使用微服务

5.5.1 注册中心

如果某个模块需要使用注册中心服务,进行如下配置:
(1)pom文件添加Consul注册中心依赖

<dependency>
	<groupId>org.springframework.cloud</groupId>
	<artifactId>spring-cloud-starter-consul-discovery</artifactId>
</dependency>

(2)修改配置文件,添加服务注册配置

spring:
  cloud:
    consul:
      host: localhost
      port: 8500
      discovery:
        serviceName: ${spring.application.name}

(3)修改启动类,添加@EnableDiscoveryClient,开启注册发现

启动注册中心服务和该模块,访问http://localhost:8500进入管理界面查看到该模块即为成功。

5.5.2 系统服务监控

如果某个模块需要使用监控服务,进行如下配置:
(1)pom文件添加客户端依赖

<dependency>
	<groupId>de.codecentric</groupId>
	<artifactId>spring-boot-admin-starter-client</artifactId>
	</dependency>
<version>2.2.3</version>

(2)修改配置文件,添加服务监控配置

spring:
  boot:
    admin:
      client:
        url: "http://localhost:8000"
management:
  endpoints:
    web:
      exposure:
        include: "*"
  endpoint:
    health:
      show-details: ALWAYS

启动jee-fast-monitor服务和该模块,访问http://localhost:8000进入监控界面查看到该模块即为成功。

5.5.3 服务消费

服务提供者模块:jee-fast-producer*,执行JeeFastProducerApplication启动服务。
服务消费者模块:jee-fast-consumer,执行JeeFastConsumerApplication启动服务。

jee-fast-consumer服务消费者调用jee-fast-producer*服务提供者接口,提供了三种方式的示例:
(1)RestTemplate:RestTemplate:CallController.java
(2)RestTemplate + Ribbon注解:RibbonCallController.java
(3)Fegin声明式:FeginCallController.java
依次启动注册中心、服务提供者、服务消费者项目,访问jee-fast-consumer提供的示例接口,返回正确信息即为成功。

5.5.4 服务熔断

如果服务消费者需要使用服务熔断,进行如下配置:
因为Feign中已经依赖了Hystrix,所以不需要再依赖Hystrix了。

(1)修改配置文件,添加服务熔断配置

feign: 
  hystrix:
    enabled: true

(2)创建失败回调处理类
创建回调类,实现需要熔断器的Service接口,实现对应的方法,返回调用失败后的信息(示例):

@Component
public class ProducerHystrixFallback implements ProducerService {
	@RequestMapping("hello")
	public String hello() {
		// 返回调用失败后的信息
		return "sorry, hello service call failed!";
	}
}

Feign声明式服务接口的@FeignClient注解中添加fallback属性,绑定该失败回调处理类。

@FeignClient(name = "jee-fast-producer", fallback = ProducerHystrixFallback.class)
public interface ProducerService {
	@RequestMapping("hello")
	public String hello();
}

(3)Feign接口(示例)

@RestController
public class FeignCallController {
	@Autowired
	private ProducerService producerService;
	
	@RequestMapping("feign/call")
	public String call() {
		return producerService.hello();
	}
}

启动成功后,多次访问feign接口http://localhost:8005/feign/call返回正确结果,关闭调用的producer服务,再次访问,返回熔断回调信息,则说明熔断成功,重启producer服务,再次访问,服务可以访问,说明熔断器具有自我诊断功能。

如果需要使用熔断监控服务,请运行jee-fast-hystrix模块,执行JeeFastHystrixApplication启动服务。
启动成功后,访问http://localhost:8501/hystrix,在监控地址内输入http://localhost:8005/hystrix.stream,点击Monitor Stream开始监控,查看对应服务的熔断监控信息。输入http://localhost:8501/turbine.stream,可以查看Turibine聚合多个Hytrix消费者的熔断监控信息

5.5.5 服务网关

如果需要使用服务网关,请运行jee-fast-zuul模块,执行JeeFastZuulApplication启动服务。

访问示例接口:http://localhost:8010/fegin/call,返回正确结果,即说明Zuul成功转发请求并成功调用后端微服务。

5.5.6 链路追踪

如果需要使用链路追踪服务,必须安装ZipKin和Elasticsearch,并启动ZipKin服务。

如果某个模块需要使用链路追踪服务,进行如下配置:
(1)pom文件添加ZipKin依赖

<dependency>
	<groupId>org.springframework.cloud</groupId>
	<artifactId>spring-cloud-starter-zipkin</artifactId>
</dependency>

(2)修改配置文件,添加ZipKin配置

# 配置zipkin
spring:
  zipkin: 
    base-url: http://localhost:9411
  sleuth:
    sampler:
      # 样本采集量,默认为0.1
      probability: 1

启动成功后,访问其接口会产生ZipKin数据,可以访问http://localhost:9411查看服务调用信息。

5.5.7 配置中心

如果需要配置中心服务,请运行jee-fast-config模块,执行JeeFastConfigApplication启动服务。
需要提前创建GIT配置仓库,放置配置文件。
启动成功后仓库中的配置文件会被转换成相应的Web接口,规则为:

  • /{application}/{profile}[/{label}]
  • [/{label}]/{application}-{profile}.yml
  • [/{label}]/{application}-{profile}.properties

例如访问http://localhost:8020/consumer/dev返回dev配置文件的信息,访问http://localhost:8020/consumer-dev.properties返回配置文件的具体内容。

需要某个模块需要使用配置中心服务,进行如下配置:
(1)pom文件添加config依赖

<dependency>
	<groupId>org.springframework.cloud</groupId>
	<artifactId>spring-cloud-starter-config</artifactId>
</dependency>

(2)添加bootstrap.yml配置文件
添加config的配置,并把application.yml中的consul配置移到这里,因为在通过配置中心查找配置时需要通过注册中心的发现服务。

spring:
  cloud:
    # 配置consul注册中心
    consul:
      host: localhost
      port: 8500
      discovery:
        serviceName: jee-fast-consumer
    # 配置config配置中心
    config:
      discovery:
        # 开启发现服务
        enabled: true
        # 配置中心服务名称
        serviceId: jee-fast-config
      # 对应{application}部分
      name: consumer
      # 对应{profile}部分
      profile: dev
      # git的分支,如果配置中心使用的是本地存储则该参数无用
      label: master

config的配置先于application.yml,bootstrap.yml的加载也先于application.yml。

(3)添加SpringConfigController控制器
通过注解@Value("${hello}")声明hello属性从配置文件读取。

@RefreshScope
@RestController
public class SpringConfigController {
	@Value("${hello}")
	private String hello;
	
	@RequestMapping("hello")
	public String from() {
		return this.hello;
	}
}

启动注册中心、配置中心和该项目,访问http://IP:PORT/hello返回配置信息。

(4)使用Refresh机制
添加actuator依赖,spring-boot-starter包含actuator,所以不需要再添加actuator了。
在使用配置属性的类型中加上@RefreshScope注解。
开放健康检查接口:

management:
  endpoints:
    web:
      exposure:
        include: "*"
  endpoint:
    health:
      show-details: ALWAYS

配置文件发生变化后,post请求http://IP:PORT/actuator/refresh就会更新配置文件。

当客户端数量很多时刷新手动客户端很麻烦,此时可以使用Spring Cloud Bus。

(5)使用Spring Cloud Bus
需要安装并启动RabbitMQ。
添加消息总线相关依赖:

<dependency>
	<groupId>org.springframework.cloud</groupId>
	<artifactId>spring-cloud-starter-bus-amqp</artifactId>
</dependency>

修改配置bootstrap.yml,添加RabbitMQ相关配置:

spring:
  rabbitmq:
    host: localhost
    port: 5672
    username: guest
    password: guest
  • 解决客户端报错:No bean named 'configServerRetryInterceptor' available:
    添加刷新拦截器配置:
public class RetryConfig {
	@Bean
	@ConditionalOnMissingBean(name = "configServerRetryInterceptor")
	public RetryOperationsInterceptor configServerRetryInterceptor() {
		return RetryInterceptorBuilder.stateless().backOffOptions(1000, 1.2, 5000).maxAttempts(10).build();
	}
}

resources下新建/META-INF/spring.factories:

org.springframework.cloud.bootstrap.BootstrapConfiguration=com.ywy.consumer.config.RetryConfig

配置文件发生变化后,post请求http://localhost:8020/actuator/bus-refresh更新所有客户端的配置文件。

6 关键技术

6.1 Spring Boot

Spring Boot是由Pivotal团队提供,设计用来简化新Spring应用的初始搭建以及开发过程的开源框架。该框架遵循约定优于配置的规则,使用特定的方式来进行配置,从而使开发人员不再需要定义样板化的配置。

6.2 Spring Cloud

Spring Cloud是一个微服务框架,提供了一整套分布式系统解决方案。它为微服务架构开发中所涉及的服务治理、服务熔断、智能路由、链路追踪、消息总线、配置管理、集群状态等操作都提供了一种简单的开发方式。

Spring Cloud组件:

  1. Netflix Eureka:基于REST服务的服务治理组件,包括服务注册中心、服务注册与服务发现机制的实现。
  2. Netflix Hystrix:容错管理工具,实现断路器模式,通过控制服务的节点,从而对延迟和故障提供更强大的容错能力。
  3. Netflix Ribbon:实现客户端负载均衡的服务调用组件。
  4. Netflix Feign:基于Ribbon和Hystrix的声明式服务调用组件。
  5. Netflix Zuul:微服务网关,提供动态路由,访问过滤等服务。
  6. Spring Cloud Config:配置管理工具,支持使用Git存储配置内容,支持应用配置的外部化存储,支持客户端配置信息刷新、加解密配置内容等。
  7. Spring Cloud Bus:事件、消息总线,用于在集群中传播状态变化,可与Spring Cloud Config联合实现热部署。
  8. Spring Cloud Sleuth:日志收集工具包,封住了Dapper、ZipKin和HTrace操作。
  9. Spring Cloud Consul:封装了Consul操作,Consul是一个服务发现与配置工具。
  10. Spring Cloud Zookeeper:操作Zookeeper的工具包,用于使用zookeeper方式的服务注册和发现。
  11. Spring Cloud Stream:数据流操作开发包,封装了与Redis、Rabbit、Kafka等发送接收消息的接口。
  12. Spring Cloud Data Flow:大数据操作工具,通过命令行方式操作数据流。
  13. Spring Cloud Security:安全工具包,为应用程序添加安全控制,主要指OAuth2。

6.3 Spring Security

Spring Security是一个强大且支持高度自定义的安全框架,可以为系统在登录认证和访问授权两大核心安全方面提供强有力的保障。

6.4 MyBatis

MyBatis是一款非常优秀的持久层框架,可以支持定制化SQL、存储过程以及高级映射等高级特性。MyBatis可以使用简单的XML或注解来配置和映射原生信息,将接口和Java的POJOs对象映射成数据库中的记录,使用MyBatis可以避免几乎所有的JDBC代码,无须手动设置参数和获取结果集。

6.5 Vue.js

Vue.js是一套构建用户界面的渐进式框架,Vue只关注视图层,采用自底而上增量开发的设计方式,Vue的目标是通过尽可能简单的API实现响应的数据绑定和组合的视图组件。

6.6 Element

Element是饿了么开源的一套前端UI框架,通过了较为丰富的组件,界面简洁优雅。Element分别提供了Vue.js、React和Angular的实现。

6.7 系统服务监控(Spring Boot Admin)

Spring Boot Admin是一个管理和监控Spring Boot应用程序的开源监控软件,针对spring-boot的actuator接口进行UI美化并封装,乐意在管理界面中浏览所有被监控spring-boot项目的基本信息,详细的Health信息、内存信息、JVM信息、垃圾回收信息、各种配置信息(如数据源、缓存列表和命中率)等,还可以直接修改logger的level,Spring Boot Admin提供的丰富详细的监控信息给Spring Boot应用的监控、维护和优化都带来了极大的便利。

6.8 注册中心(Consul)

Consul是HashiCorp公司推出的开源工具,用于实现分布式系统的服务发现与配置。与其他分布式服务注册与发现的方案相比,Consul的方案更“一站式”,内置了服务注册与发现框架、分布一致性协议实现、健康检查、Key/Value存储、多数据中心方案,不再需要依赖其他工具(比如ZooKeeper等),使用起来也比较简单。Consul使用Go语言编写,因此具有天然可移植性(支持Linux、Windows和Mac OS X);安装包仅包含一个可执行文件,方便部署,与Docker等轻量级容器可无缝配合。

6.9 服务消费(Ribbon、Feign)

在单体应用中,代码可以直接依赖,在代码中直接调用即可,但在微服务架构(分布式架构)中,服务都运行在各自的进程之中,甚至部署在不同的主机和不同的地区,就需要相关的远程调用技术了。
Spring Cloud体系里应用比较广泛的服务调用方式有两种:
(1)使用RestTemplate进行服务调用,可以通过Ribbon注解RestTemplate模板,使其拥有负载均衡的功能。
(2)使用Feign进行声明式服务调用,声明之后就行调用本地方法一样,Feign默认使用Ribbon实现负载均衡。

6.9.1 Ribbon

Ribbon是Netflix发布的负载均衡器,它有助于控制HTTP和TCP的客户端的行为。为Ribbon配置服务提供者地址后,Ribbon就可基于某种负载均衡算法自动地帮助服务消费者去请求。Ribbion默认为我们提供了很短负载均衡算法,例如轮询、随机。我们也可以为Ribbon实现自定义的负载均衡算法。

Ribbon内置负载均衡策略:
Ribbon内置负载均衡策略

6.9.2 Feign

Spring Cloud Feign是一套基于Netflix Feign实现的声明式服务调用客户端,使编写Web服务客户端变得更加简单。我们只需要通过创建接口并用注解来配置它即可完成对Web服务接口的绑定。它具备可插拔的注解支持,包括Feign注解、JAX-RS注解。它也支持可插拔的编码器和解码器。Spring Cloud Feign还扩展了对Spring MVC注解的支持,同时还整合了Ribbon来提供均衡负载的HTTP客户端实现。

6.10 服务熔断(Hystrix、Turbine)

6.10.1 雪崩效应

在微服务架构中,服务众多,通常会涉及多个服务层级的调用,一旦基础服务发生故障,很可能会导致级联故障,进而造成整个系统不可用,这种现象被称为服务雪崩效应。
服务雪崩效应是一种因“服务提供者”的不可用导致“服务消费者”的不可用并将这种不可用逐渐放大的过程。

6.10.2 熔断器(CircuitBreaker)

熔断器如果电力过载保护器,它可以实现快速失败,如果它在一段时间内侦测到许多类似的错误,就回强迫其以后的调用快速失败,不再访问远程服务器,从而防止应用程序不断地尝试执行可能会失败的操作,使得应用程序继续执行而不用等待修正错误,或者浪费CPU时间去等到长时间的超时产生。熔断器也可以使应用程序能够诊断错误是否已经修正,如果已经修正,应用程序会再次尝试调用操作。熔断器模式就像是那些容易导致错误操作的一种代理。这种代理能够记录最近调用发生错误的次数,然后决定使用允许操作继续,或者立即返回错误。熔断器是保护服务高可用的最后一道防线。

6.10.3 Hystrix特性

(1)断路器机制
当Hystrix Command请求后端服务失败数量超过一定比例,断路器会切换到开路状态(OPEN)。这时所有请求会直接失败而不会发送到后端服务。断路器保持在开路状态一段时间后,自动切换到半开路状态(HALF-OPEN)。这时会判断下一次请求的返回情况,如果请求成功,断路器切回闭路状态(CLOSE),否则重新切换到开路状态。一点后端服务不可用,断路器就回直接切断请求链,避免发送大量无效请求,从而影响系统吞吐量,并且断路器有自我检测并恢复的能力。
(2)fallback
fallback相当于降级操作。对于查询操作,我们可以实现一个fallback方法,当请求后端服务出现异常时,可以使用fallback方法返回的值。fallback方法的返回值一般是设置的默认值或者来自缓存。
(3)资源隔离
在Hystrix中主要通过线程池来实现资源隔离。在使用时根据调用的远程服务划分出多个线程池。这样做的优点是运行环境被隔离开了,就算调用服务的代码存在bug或者由于其他原因导致自己所在的线程池被耗尽,也不会对系统的其他服务造成影响,但代价就是维护多个线程池会对系统带来额外的性能开销。如果对性能有严格要求而且确信自己调用服务的客户端不会出现问题,就可以使用Hystrix的信号模式(Semaphores)来隔离资源。

6.10.4 Hystrix Dashboard

Hystrix Dashboard是一款针对Hystrix进行实时监控的工具,通过Hystrix Dashboard我们可以直观地看到各Hystrix Command的请求响应时间、请求成功率等数据。 Hystrix Dashboard支持3种监控方式:
(1)单体Hystrix消费者:通过URL http://hystrix-app:port/hystrix.stream开启,实现对具体某个服务实例的监控。
(2)默认集群监控:通过URL http://turbine-hostname:port/turbine.stream开启,实现对默认集群的监控。
(3)自定义集群监控:通过URL http://turbine-hostname:port/hostname.stream?cluster=[clusterName]开启,实现对clusterName集群的监控。

监控界面参数说明:
参数说明

6.10.5 Spring Cloud Turbine

汇总系统内多个服务的数据并显示到Hystrix Dashboard上。

6.11 服务网关(Zuul)

让客户端直接与各个微服务通信会有以下几个问题:
(1)客户端会多次请求不同的微服务,增加客户端的复杂性。
(2)存在跨域请求,在一定场景下处理会变得相对比较复杂。
(3)实现认证复杂,每个微服务都需要独立认证。
(4)难以重构,项目迭代可能导致微服务重新划分,如果客户端直接与微服务通信,那么重构将会很难实施。
(5)如果某些微服务使用了防火墙/浏览器不友好的协议,直接访问会有一定困难。

使用服务网关具有以下几个优点:
(1)易于监控。可在微服务网关收集监控数据并将其推送到外部系统进行分析。
(2)易于认证。可在服务网关上进行认证,然后转发请求到微服务,无须在每个微服务中进行认证。 (3)客户端只跟服务网关打交道,减少了客户端与各个微服务之间的交互次数。
(4)多渠道支持,可以根据不同客户端(Web端、移动端、桌面端等)提供不同的API服务网关。

6.11.1 Spring Cloud Zuul

服务网关是微服务架构中一个不可或缺的部分。在通过服务网关统一向外系统提供REST API的过程中,除了具备服务路由、均衡负载功能之外,它还具备了权限控制等功能。
Spring CloudNetflix中的Zuul就担任了这样的角色,为微服务通过了前门保护的作用,同时将权限控制这些比较重的非业务逻辑内容迁移到服务路由层面,使得服务集群主体能够具备更高的可复用性和可测试性。
在Spring Cloud体系中Spring Cloud Zuul封装了Zuul组件,作为一个API网关,负责提供负载均衡、反向代理和权限认证。

Zuul作为API网关服务,不同的客户端使用不同的负载将请求统一分发到后端的Zuul,再由Zuul转发到后端服务。为了保证Zuul的高可用,前端可以同时开启多个Zuul实例进行负载均衡。另外,Zuul的前端还可以使用Nginx或则F5再次进行负载均衡,从而保证Zuul的高可用性。

6.11.2 Zuul工作机制

(1)过滤器机制
Zuul的核心是一系列的filters,其作用类似Servlet框架的Filter,Zuul把客户端请求路由到业务处理逻辑过程中,这些filter在路由的特定时期参与了一些过滤处理,比如实现鉴权、流量转发、请求统计等功能。
Zuul运行机制:
Zuul运行机制

(2)过滤器的生命周期
过滤器的生命周期分别为PRE、ROUTING、POST、ERROR。
Zuul过滤器的生命周期

Zuul中定义了四种标准过滤器类型,对应于请求的典型生命周期。基于这些过滤器可以实现各种丰富的功能。

  • PRE:这种过滤器在请求被路由之前调用。我们可利用这种过滤器实现身份验证、在集群中选择请求的微服务、记录调试信息等。
  • ROUTING:这种过滤器将请求路由到微服务。这种过滤器用于构建发送给微服务的请求,并使用Apache HttpClient或Netfilx Ribbon请求微服务。
  • POST:这种过滤器在路由到微服务以后执行。这种过滤器可用来为响应添加标准的HTTP Header、收集统计信息和指标、将响应从微服务发送给客户端等。
  • ERROR:在其他阶段发生错误时执行该过滤器。

Zuul默认实现的Filter:
Zuul默认实现的Filter

除了默认的过滤器类型,Zuul允许我们创建自定义的过滤器类型。自定义过去器需要继承ZuulFilter,并实现ZuulFilter中的抽象方法。

(3)禁用指定的Filter
可以在application.yml中配置需要禁用filter,格式为zuul.[SimpleClassName].[filterType].disable=true。

6.11.3 默认路由规则

通过添加路由配置进行请求转发:

zuul:
  # 接口前缀
  # prefix: /v1
  # 配置路由转发规则(示例)
  routes:
    ribbon:
      path: /ribbon/**
      serviceId: jee-fast-consumer
    feign:
      path: /feign/**
      serviceId: jee-fast-consumer

如果后端微服务非常多,每一个都这样配置很麻烦,Spring Cloud Config已经帮我们做了默认配置。默认情况下,Zuul会代理所有注册到注册中心的微服务,并且Zuul的默认路由规则如下:http://ZUUL_HOST:ZUUL_PORT/[微服务在注册中心的serviceId]/**会被转发到serviceId对应得微服务。如果遵循默认路由规则,基本就没什么配置了。

6.11.4 路由熔断

Zuul作为Netflix组件,可以与Ribbon、Eureka和Hystrix等组件相结合,实现负载均衡、熔断器的功能。默认情况下Zuul和Ribbon相结合,实现了负载均衡。实现熔断器功能需要实现FallbackProvider接口。
实现该接口有两个方法:
(1)getRoute(),用于指定熔断器功能应用于哪些路由的服务,如果需要所有的路由都加熔断功能,则返回"*";
(2)fallbackResponse(),为进入熔断器功能时执行的逻辑。

6.12 链路追踪(Sleuth、Zipkin)

在微服务架构中,随着业务发展,系统拆分导致系统调用链路愈发复杂,一个看似简单的前端请求可能最终需要调用很多次后端服务才能完成,那么当整个请求出现问题时,我们很难得知到底是哪个服务出了问题导致的,这是就需要解决一个问题,即如何快速定位服务故障点,分布式系统调用链路追踪技术就此诞生了。

6.12.1 ZipKin

ZipKin是一个由Twitter公司提供并开源的分布式的跟踪系统,它可以帮助收集服务的时间数据,以解决微服务架构中的延迟问题,包括数据的收集、存储、查找和展现。
每个服务向ZipKin报告定时数据,ZipKin会根据调用关系通过ZipKin UI生成依赖关系图,展示多少跟踪请求经过了哪些服务,该系统让开发者可通过一个Web前端轻松地收集和分析数据,例如用户每次请求服务的处理时间等,可非常方便地监测系统中存在的瓶颈。
ZinKin提供了可插拔数据存储方式:In-Memory、MySQL、Cassandra以及Elasticsearch。我们可以根据需求选择不同的存储方式,生成环境一般都需要持久化。

6.12.2 Spring Cloud Sleuth

一般而言,一个分布式服务追踪系统,主要由3部分组成:数据收集、数据存储和数据展示。
Spring Cloud Sleuth为服务之间的调用提供链路追踪,提供Sleuth可以很清楚地了解到一个服务请求经过了哪些服务,每个服务处理花费了多长时间,从而让我们可以很方便地理清各微服务间的调用关系。此外,Sleuth还可以帮助我们:
(1)耗时分析:通过Sleuth可以很方便地了解到每个采样请求的耗时,从而分析出哪些服务调用比较耗时。
(2)可视化错误:对于程序未捕捉的异常,可以通过集成ZipKin服务在界面上看到。
(3)链路优化:对于调用比较频繁的服务,可以针对这些服务实施一些优化措施。
Spring Cloud Sleuth可以结合ZipKin,将信息发送给ZipKin,利用ZipKin的存储来存储信息,利用ZipKin UI来展示数据。

6.13 配置中心(Spring Config)

在分布式系统中,每个项目都有各种配置文件,且随着服务的增加而不断增多。某一个基础服务信息变更都会导致一系列服务的更新和重启,运维麻烦,极易出错。配置中心便由此应运而生。
目前市面上的配置中心很多,如Spring Cloud Config、Apache Commons Configuration、淘宝的diamond、百度的disconf、360的QConf等。

6.13.1 Spring Cloud Config

Spring Cloud Config是一套为分布式系统中的基础设施和微服务应用提供集中化配置的管理方案,分为服务端与客户端两个部分。服务端也称为分布式配置中心,是一个独立的微服务应用,用来连接配置仓库并为客户端提供获取配置信息。客户端是微服务架构中的各个微服务应用或基础设施,它们通过指定的配置中心来管理服务相关的配置内容,并在启动时从配置中心获取和加载配置信息。
Spring Cloud Config对服务端和客户端中的环境变量和属性配置实现了抽象映射,所以除了适用于Spring应用,也可以在任何其他语言中使用。Spring Cloud Config实现的配置中心默认采用Git来存储配置信息,所以使用Spring Cloud Config构建的配置服务器天然就支持对微服务应用配置信息的版本管理,并且可以通过Git客户端工具非常方便地管理和访问配置内容。当然它也提供了对其他存储方式的支持,如SVN仓库、本地化文件系统等。

6.13.2 Refresh机制

Spring Boot项目只有在启动时加载配置文件信息,Git仓库配置修改后,虽然配置中心服务器能够读取最新的提交信息,但配置中心客户端确不会重新读取,以至于不能基石地读取更新后的配置信息。
Refresh机制是Spring Cloud Config提供的一种刷新机制,它允许客户端提供POST方法触发各自的/refresh,主要依赖spring-boot-starter-actuator包就拥有了/refresh的功能。

6.13.3 Spring Cloud Bus

Spring Cloud Bus被大家称为消息总线,通过轻量级的消息代理来连接各个分布的节点,可以利用消息对列的广播机制在分布式系统中进行消息传播。通过消息总线可以实现很多业务功能,其中对于配置中心客户端刷新就是一个非常典型的使用场景。
消息总线的作用流程:
消息总线的作用流程
Spring Cloud Bus进行配置更新的步骤如下:

  1. 提交代码触发post请求给/actuator/bus-refresh。
  2. Server端接收到请求并发给Spring Cloud Bus。
  3. Spring Cloud Bus接到消息并通知给其他客户端。
  4. 其他客户端接收到通知,请求Server端获取最新配置。
  5. 全部客户端均获取到最新的配置。

7 数据库设计

7.1 数据库设计原则

  1. 表的主键采用长整型的“编号”字段
  2. 所有表共有字段:编号、创建人、创建时间、更新人、更新时间
  3. 表间关系采用各表编号进行关联查询,不定义数据库外键

7.2 数据库表结构

(1)用户表(sys_user)
用户表包含用户信息,主要有编号、用户名、昵称、密码、邮箱、手机号等字段,通过dept_id与机构表关联,表明所属机构。
(2)角色表(sys_role)
角色表代表用户角色,用户拥有角色,角色拥有菜单,菜单拥有权限标识。所以不同的角色拥有不同的权限,角色表主要有编号、角色名、备注等字段。
(3)机构表(sys_dept)
机构代表一种组织机构,可以有子机构,用户归属于机构。机构表主要有编号、机构名称、上级机构等字段。
(4)菜单表(sys_menu)
菜单分为目录、菜单和操作按钮三种类型,可以进行权限控制,菜单表主要有编号、菜单名称、父菜单、菜单类型、菜单图标、菜单URL、菜单权限等字段 (5)用户角色表(sys_user_role)
用户角色表是用户和角色的中间表,通过用户id和角色id分别和用户表和角色表关联。
(6)角色菜单表(sys_role_menu)
角色菜单表是角色和菜单的中间表,通过角色id和菜单id分别和角色表和菜单表关联。
(7)角色机构表(sys_role_dept)
角色机构表是角色和机构的中间表,通过角色id和机构id分别和角色表和机构表关联。
(8)字典表(sys_dict)
字典表主要存储系统采用的枚举类型数据,主要包含编号、标签、数据值、类型等字段。
(9)配置表(sys_config)
配置表主要存储系统配置信息,主要包含编号、标签、数据值、类型等字段。
(10)操作日志表(sys_log)
操作日志表主要记录系统用户的日常操作信息,主要包含编号、用户名、用户操作、请求方法、请求参数、执行时长、IP地址等字段。
(11)登录日志表(sys_login_log)
登录日志表主要记录用户登录和退出状态,主要包含编号、用户名、登录状态、IP地址等字段,可以根据status状态统计在线用户信息。

8 跨域解决方案

8.1 什么是跨域

同源策略:为了保障浏览器的安全,不同源的客户端脚本在没有明确授权的情况下,不能读写对方资源。同源策略是浏览器安全的基石。
如果一个请求地址里协议、域名和端口号都相同就属于同源。

依据浏览器的同源策略,非同源脚本不可操作其他源下的对象,如果想要操作就需要跨域。
在同源策略下,非同源的网站之间不能发送Ajax请求,如果需要,可通过降域或其他技术实现。

8.2 CORS技术

为了解决浏览器跨域问题,W3C提出了跨域资源共享方案,即CORS(Cross-Origin Resource Sharing)。
CORS可以在不破坏既有规则的情况下,通过后端服务器实现CORS接口,从而实现跨域通信。CORS将请求分为简单请求和非简单请求,分别对跨域通信提供了支持。

8.2.1 简单请求

简单请求:
(1)请求方式只能是:HEAD、GET、POST
(2)请求头信息只能包含以下字段:

  • Accept
  • Accept-Language
  • Content-Language
  • Content-Type(仅限于application/x-www-form-urkencoded、multipart/form-data、text/plain类型)

对于简单请求,CORS的策略是请求时在请求头中增加一个Origin字段,服务器收到请求后,根据该字段判断是否允许该请求访问。
如果允许,就在HTTP头信息中添加以下字段,并返回正确结果:

  • Access-Control-Allow-Origin:指定允许请求的域
  • Access-Control-Allow-Credentials:可选,是否允许后续请求携带验证信息(cookies)
  • Access-Control-Expose-Headers:可选,允许客户端拿到的字段。无论是否设置,Cache-Control、Content-Language、Content-Type、Expires、Last-Modified、Pragma都可以拿到。

8.2.2 非简单请求

对于非简单请求的跨域请求,浏览器会在真实请求发出前增加一次OPTION请求,称为预检请求(preflight request)。预检请求会将真实请求的信息添加到HTTP头信息字段中,询问服务器是否允许这样的操作。
与简单请求相比,除了Origin,还多了:

  • Access-Control-Request-Method:请求使用的HTTP方法
  • Access-Control-Request-Headers:请求中包含的自定义头字段

服务器收到请求时,需要对Origin、Access-Control-Request-Method、Access-Control-Request-Headers分别进行验证,验证通过后,会在返回HTTP头信息中添加:

  • Access-Control-Allow-Origin:指定允许请求的域
  • Access-Control-Allow-Methods:服务器允许的所有请求方法
  • Access-Control-Allow-Headers:服务器允许的所有请求头字段
  • Access-Control-Allow-Credentials:是否允许后续请求携带验证信息(cookies)
  • Access-Control-Max-Age:预检请求的有效期,单位为秒。有效期内不会重复发送预检请求。

当预检请求通过后,浏览器才会发送真实请求到服务器,这样就实现了跨域资源的请求访问。

8.3 CORS实现

@Configuration
public class CorsConfig implements WebMvcConfigurer {
	@Override
	public void addCorsMappings(CorsRegistry registry) {
		registry.addMapping("/**") // 允许跨域访问的路径
		.allowedOrigins("*")  // 允许跨域访问的源
		.allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")  // 允许跨域访问的请求方法
		.allowedHeaders("*") // 允许的请求头字段
		.allowCredentials(true) // 允许后续请求携带验证信息(cookie)
		.maxAge(16800); // 预检请求有效期
	}
}
GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007 Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The GNU Affero General Public License is a free, copyleft license for software and other kinds of works, specifically designed to ensure cooperation with the community in the case of network server software. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, our General Public Licenses are intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. Developers that use our General Public Licenses protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License which gives you legal permission to copy, distribute and/or modify the software. A secondary benefit of defending all users' freedom is that improvements made in alternate versions of the program, if they receive widespread use, become available for other developers to incorporate. Many developers of free software are heartened and encouraged by the resulting cooperation. However, in the case of software used on network servers, this result may fail to come about. The GNU General Public License permits making a modified version and letting the public access it on a server without ever releasing its source code to the public. The GNU Affero General Public License is designed specifically to ensure that, in such cases, the modified source code becomes available to the community. It requires the operator of a network server to provide the source code of the modified version running there to the users of that server. Therefore, public use of a modified version, on a publicly accessible server, gives the public access to the source code of the modified version. An older license, called the Affero General Public License and published by Affero, was designed to accomplish similar goals. This is a different license, not a version of the Affero GPL, but Affero has released a new version of the Affero GPL which permits relicensing under this license. The precise terms and conditions for copying, distribution and modification follow. TERMS AND CONDITIONS 0. Definitions. "This License" refers to version 3 of the GNU Affero General Public License. "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. "The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. A "covered work" means either the unmodified Program or a work based on the Program. To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 1. Source Code. The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. The Corresponding Source for a work in source code form is that same work. 2. Basic Permissions. All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 3. Protecting Users' Legal Rights From Anti-Circumvention Law. No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 4. Conveying Verbatim Copies. You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 5. Conveying Modified Source Versions. You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: a) The work must carry prominent notices stating that you modified it, and giving a relevant date. b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 6. Conveying Non-Source Forms. You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. "Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 7. Additional Terms. "Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or d) Limiting the use for publicity purposes of names of licensors or authors of the material; or e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 8. Termination. You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 9. Acceptance Not Required for Having Copies. You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 10. Automatic Licensing of Downstream Recipients. Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 11. Patents. A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 12. No Surrender of Others' Freedom. If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 13. Remote Network Interaction; Use with the GNU General Public License. Notwithstanding any other provision of this License, if you modify the Program, your modified version must prominently offer all users interacting with it remotely through a computer network (if your version supports such interaction) an opportunity to receive the Corresponding Source of your version by providing access to the Corresponding Source from a network server at no charge, through some standard or customary means of facilitating copying of software. This Corresponding Source shall include the Corresponding Source for any work covered by version 3 of the GNU General Public License that is incorporated pursuant to the following paragraph. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the work with which it is combined will remain governed by version 3 of the GNU General Public License. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of the GNU Affero General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU Affero General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU Affero General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future versions of the GNU Affero General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 15. Disclaimer of Warranty. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. Limitation of Liability. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 17. Interpretation of Sections 15 and 16. If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. <one line to give the program's name and a brief idea of what it does.> Copyright (C) <year> <name of author> This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. Also add information on how to contact you by electronic and paper mail. If your software can interact with users remotely through a computer network, you should also make sure that it provides a way for users to get its source. For example, if your program is a web application, its interface could display a "Source" link that leads users to an archive of the code. There are many ways you could offer source, and different solutions will be better for different programs; see section 13 for the specific requirements. You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU AGPL, see <http://www.gnu.org/licenses/>.

简介

基于SpringBoot、Vue.js、Element UI等主流前后端技术,采用前后端分离架构实现的后台权限管理系统 展开 收起
JavaScript 等 4 种语言
AGPL-3.0
取消

发行版

暂无发行版

贡献者 (2)

全部

近期动态

不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化