### 系统说明 - 定位JAVA开发多模块架构;功能聚合;服务分离;轻量级快速开发框架 - 内置基于OAuth2 的 RBAC 权限管理系统 - 基于网关统一路由所有服务,可实现动态负载均衡 - 前置网关加解密、请求限流、header头清洗 - 内置定时任务统一调度 - 支持容器化一键部署架构 - 管理后台基于vue3的element-plus开发 - 可无缝对接nacos、dubbo、spring-cloud ### 后端版本说明 | Jdk | 17 | |-----------------------------|-------| | Spring Boot | 3.1.5 | | Mybatis Plus | 3.5.4 | | hutool | 5.8.2 | | Spring Authorization Server | 1.1.3 | ### 模块说明 ``` kxs └── kxs-admin-ui-- 后台管理页面 └── kxs-codegen-- 代码生成模块[4002] └── kxs-common -- 系统公共模块 ├── kxs-common-core -- 公共工具核心包 ├── kxs-common-datasource -- 动态数据源 ├── kxs-common-log -- 异步日志服务 ├── kxs-common-mybatis -- mybatis 扩展封装 ├── kxs-common-security -- oauth2 工具包 鉴权登录 ├── kxs-gateway -- Gateway网关[9999] ├── kxs-quartz-- 定时任务模块[4000] └── kxs-system-- 通用用户权限管理模块 └── kxs-system-api -- 通用用户权限管理系统公共api模块 └── kxs-system-biz -- 通用用户权限管理系统业务处理模块[8080] ``` ### 快速开始 **导入db文件下的sql语句** **开启本地redis** ### 后端启动 ``` 1.kxs-gateway/KxsGatewayApplication.java 2.kxs-system-biz/KxsAdminApplication.java 3.kxs-codegen/KxsCodeGenApplication.java 代码生成按需启动 4.kxs-quartz/KxsQuartzApplication.java 定时任务按需启动 ``` ### 管理后台启动 ``` # 检查node版本 = 16 node -v # 若高版本node 可执行n 命令切换至 16 版本 n 16.17.1 # 切换到kxs-admin-ui目录下依次执行 npm install --registry=https://registry.npmmirror.com npm run dev ``` ### 访问管理后台 ``` 浏览器访问: http://localhost:8888 默认用户名: admin 默认密码: 123456 ``` ### Gateway网关 网关采用的是spring官方的网关组件,通过异步背压的高性能网关。路由配置是整个架构最为核心的功能 网关内置了图形验证码以及验证逻辑,基于webflux 响应式接口实现 **路由及限流配置** ``` routes: #ADMIN 模块 - id: kxs-system-biz # 唯一的服务ID uri: lb://kxs-system-biz # instances下的服务名称,实现负载均衡 predicates: - Path=/v1/kxs/admin/** #当前服务的请求前缀, filters: # 过滤前缀 - StripPrefix=3 # 限流配置 - name: RequestRateLimiter args: key-resolver: '#{@remoteAddrKeyResolver}' #SPEL表达式去的对应的bean redis-rate-limiter.replenishRate: 100 # 令牌桶每秒填充平均速率 redis-rate-limiter.burstCapacity: 200 # 令牌桶总容量 # 验证码处理 - ValidateCodeGatewayFilter #如果该服务需要验证码则开启此过滤器 # 解密过滤器 - RequestDecoderFilter ``` **网关跨域支持** ``` spring: cloud: gateway: globalcors: corsConfigurations: '[/**]': allowedOriginPatterns: "*" allowed-methods: "*" allowed-headers: "*" allow-credentials: true exposedHeaders: "Content-Disposition,Content-Type,Cache-Control" ``` **网关加解密** 解密使用的是标准的aes对称加密 ``` 解密关键方法 BodyInserter, ReactiveHttpOutputMessage> bodyInserter = BodyInserters .fromPublisher(modifiedBody, String.class); HttpHeaders headers = new HttpHeaders(); headers.putAll(exchange.getRequest().getHeaders()); headers.remove(HttpHeaders.CONTENT_LENGTH); // 创建CachedBodyOutputMessage并且把请求param加入 CachedBodyOutputMessage outputMessage = new CachedBodyOutputMessage(exchange, headers); return bodyInserter.insert(outputMessage, new BodyInserterContext()).then(Mono.defer(() -> { ServerHttpRequestDecorator decorator = new ServerHttpRequestDecorator(exchange.getRequest()) { @Override public Flux getBody() { return outputMessage.getBody(); } }; return chain.filter(exchange.mutate().request(decorator).build()); })); ``` ### 认证授权 **登陆授权流程图** ![流程图](1700399839501.jpg) **后续文档编写中...**