• 谷粒商城-基础篇(项目简介&项目搭建)


    谷粒商城-基础篇-项目简介&项目搭建

    1. 项目简介

    1.1 项目背景

    1.1.1 电商模式

    市面上有 5 种常见的电商模式 B2B、B2C、C2B、C2C、O2O;

    1. B2B 模式 B2B (Business to Business), 是指商家与商家建立的商业关系。 如:阿里巴巴
    2. B2C 模式 B2C (Business to Consumer), 就是我们经常看到的供应商直接把商品卖给用户,即“商对客” 模式,也就是通常说的商业零售,直接面向消费者销售产品和服务。如:苏宁易购、京东、 天猫、小米商城
    3. C2B 模式 C2B (Customer to Business),即消费者对企业。先有消费者需求产生而后有企业生产,即先 有消费者提出需求,后有生产企业按需求组织生产
    4. C2C 模式 C2C (Customer to Consumer) ,客户之间自己把东西放上网去卖,如:淘宝,闲鱼
    5. O2O 模式 O2O 即 Online To Offline,也即将线下商务的机会与互联网结合在了一起,让互联网成为线 下交易的前台。线上快速支付,线下优质服务。如:饿了么,美团,淘票票,京东到家

    1.1.2 谷粒商城

    谷粒商城是一个 B2C 模式的电商平台,销售自营商品给客户。

    1.2 项目架构图

    1.2.1 项目微服务架构图

    在这里插入图片描述

    1.2.2 微服务划分图

    在这里插入图片描述

    1.3 项目技术&特色

    1. 前后分离开发,并开发基于 vue 的后台管理系统
    2. SpringCloud 全新的解决方案
    3. 应用监控、限流、网关、熔断降级等分布式方案 全方位涉及
    4. 透彻讲解分布式事务、分布式锁等分布式系统的难点
    5. 分析高并发场景的编码方式,线程池,异步编排等使用
    6. 压力测试与性能优化
    7. 各种集群技术的区别以及使用
    8. CI/CD 使用

    1.4 项目前置要求

    学习项目的前置知识

    1. 熟悉 SpringBoot 以及常见整合方案
    2. 了解 SpringCloud
    3. 熟悉 git,maven
    4. 熟悉 linux,redis,docker 基本操作
    5. 了解 html,css,js,vue
    6. 熟练使用 idea 开发项目

    2. 分布式基础概念

    2.1 微服务

    微服务架构风格,就像是把一个单独的应用程序开发为一套小服务,每个小服务运行在自 己的进程中,并使用轻量级机制通信,通常是 HTTP API。这些服务围绕业务能力来构建, 并通过完全自动化部署机制来独立部署。这些服务使用不同的编程语言书写,以及不同数据 存储技术,并保持最低限度的集中式管理。

    简而言之:拒绝大型单体应用,基于业务边界进行服务微化拆分,各个服务独立部署运行。

    在这里插入图片描述

    2.2 集群&分布式&节点

    集群是个物理形态,
    分布式是个工作方式。

    只要是一堆机器,就可以叫集群,他们是不是一起协作着干活,这个谁也不知道;

    分布式是指将不同的业务分布在不同的地方。
    集群指的是将几台服务器集中在一起,实现同一业务。

    分布式系统是若干计算机的集合,这些计算机对于用户来说就像单个相关系统,分布式系统是建立在网络之上的软件系统。

    例如:京东是一个分布式系统,众多业务运行在不同的机器,所有业务构成一个大型的业
    务集群。
    每一个小的业务,比如用户系统,访问压力大的时候一台服务器是不够的。
    我们就 应该将用户系统部署到多个服务器,也就是每一个业务系统也可以做集群化;

    分布式中的每一个节点,都可以做集群。 而集群并不一定就是分布式的。
    节点:集群中的一个服务器

    2.3 远程调用

    在分布式系统中,各个服务可能处于不同主机,但是服务之间不可避免的需要互相调用,我 们称为远程调用。 SpringCloud 中使用 HTTP+JSON 的方式完成远程调用

    在这里插入图片描述

    2.4 负载均衡

    在这里插入图片描述
    分布式系统中,A 服务需要调用 B 服务,B 服务在多台机器中都存在,A 调用任意一个 服务器均可完成功能。 为了使每一个服务器都不要太忙或者太闲,我们可以负载均衡的调用每一个服务器,提 升网站的健壮性。

    常见的负载均衡算法:

    2.4.1 轮询:

    为第一个请求选择健康池中的第一个后端服务器,然后按顺序往后依次选择,直 到最后一个,然后循环。

    2.4.2 最小连接:

    优先选择连接数最少,也就是压力最小的后端服务器,在会话较长的情况下 可以考虑采取这种方式。

    2.4.3 散列:

    根据请求源的 IP 的散列(hash)来选择要转发的服务器。这种方式可以一定程 度上保证特定用户能连接到相同的服务器。如果你的应用需要处理状态而要求用户能连接到和之前相同的服务器,可以考虑采取这种方式。

    2.5 服务注册/发现&注册中心

    A 服务调用 B 服务,A 服务并不知道 B 服务当前在哪几台服务器有,哪些正常的,哪些服务 已经下线。解决这个问题可以引入注册中心;

    在这里插入图片描述

    如果某些服务下线,我们其他人可以实时的感知到其他服务的状态,从而避免调用不可用的 服务

    2.6 配置中心

    在这里插入图片描述
    每一个服务最终都有大量的配置,并且每个服务都可能部署在多台机器上。我们经常需要变 更配置,我们可以让每个服务在配置中心获取自己的配置。

    配置中心用来集中管理微服务的配置信息

    2.7 服务熔断&服务降级

    在微服务架构中,微服务之间通过网络进行通信,存在相互依赖,当其中一个服务不可用时,有可能会造成雪崩效应。要防止这样的情况,必须要有容错机制来保护服务。

    在这里插入图片描述

    2.7.1 服务熔断

    a. 设置服务的超时,当被调用的服务经常失败到达某个阈值,我们可以开 启断路保护机制,后来的请求不再去调用这个服务。本地直接返回默认 的数据

    2.7.2 服务降级

    a. 在运维期间,当系统处于高峰期,系统资源紧张,我们可以让非核心业 务降级运行。降级:某些服务不处理,或者简单处理【抛异常、返回 NULL、 调用 Mock 数据、调用 Fallback 处理逻辑】。

    2.8 API 网关

    在微服务架构中,API Gateway 作为整体架构的重要组件,它抽象了微服务中都需要的公共 功能,同时提供了客户端负载均衡,服务自动熔断,灰度发布,统一认证,限流流控,日 志统计等丰富的功能,帮助我们解决很多 API 管理难

    3. 环境搭建

    3.1 安装 linux 虚拟机

    因为我用的阿里云服务器,所以跳过此步骤。

    3.2 安装 docker

    可参考之前写过的博客

    https://blog.csdn.net/weixin_42620326/article/details/125175171

    3.3 docker 安装 mysql

    可参考之前写过的博客

    docker run -p 3307:3306 --name mysql-master \
    -v /mydata/mysql-master/log:/var/log/mysql \
    -v /mydata/mysql-master/data:/var/lib/mysql \
    -v /mydata/mysql-master/conf:/etc/mysql \
    -e MYSQL_ROOT_PASSWORD=root  \
    -d mysql:5.7
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    https://blog.csdn.net/weixin_42620326/article/details/125400334

    3.4 docker 安装 redis

    3.4.1 创建目录

    mkdir -p /mydata/redis/conf
    
    • 1

    3.4.2 创建文件

    touch /mydata/redis/conf/redis.conf
    
    • 1

    在这里插入图片描述

    3.4.3 运行redis

     docker run -p 6379:6379 --name redis -v /mydata/redis/data:/data -v /mydata/redis/conf/redis.conf:/etc/redis/redis.conf -d redis:6.0.8 redis-server /etc/redis/redis.conf
    
    • 1

    3.4.4 进入redis,测试一下

    docker exec -it redis redis-cli
    set k1 v1
    
    • 1
    • 2

    由于redis没有持久化,数据保存在磁盘中,重启之后,数据会消失

    3.4.5 redis数据持久化

    pwd
    [root@longxi ~]# cd /mydata/redis/conf
    [root@longxi conf]# ls
    redis.conf
    [root@longxi conf]# vim redis.conf
    [root@longxi conf]# cat redis.conf
    appendonly yes
    [root@longxi conf]# 
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    3.4.6 redis可视化工具

    https://github.com/uglide/RedisDesktopManager/releases/tag/0.9.3

    可参考之前写过的博客

    https://blog.csdn.net/weixin_42620326/article/details/125400334

    3.5 开发环境统一

    C:\apache-maven-3.6.2\conf下的settings.xml文件
    在这里插入图片描述

    Maven

    3.5.1 配置阿里云镜像

    <mirrors>
        <mirror>
            <id>nexus-aliyunid>
            <mirrorOf>centralmirrorOf>
            <name>Nexus aliyunname>
            <url>http://maven.aliyun.com/nexus/content/groups/publicurl>
        mirror>
    mirrors>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    3.5.2 配置 jdk1.8 编译项目

    <profiles>
        <profile>
            <id>jdk-1.8id>
            <activation>
                <activeByDefault>trueactiveByDefault>
                <jdk>1.8jdk>
            activation>
            <properties>
                <maven.compiler.source>1.8maven.compiler.source>
                <maven.compiler.target>1.8maven.compiler.target>
                <maven.compiler.compilerVersion>1.8maven.compiler.compilerVersion>
            properties>
        profile>
    profiles>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14

    3.5.3 Idea&VsCode

    idea 安装 lombok、mybatisx 插件

    Vscode 安装开发必备插件
    Vetur —— 语法高亮、智能感知、Emmet 等 包含格式化功能, Alt+Shift+F (格式化全文),Ctrl+K Ctrl+F(格式化选中代码,两个 Ctrl需要同时按着)

    EsLint —— 语法纠错
    Auto Close Tag —— 自动闭合 HTML/XML 标签
    Auto Rename Tag —— 自动完成另一侧标签的同步修改
    JavaScript(ES6) code snippets — — ES6 语 法 智 能 提 示 以 及 快 速 输 入 , 除 js 外 还 支 持.ts,.jsx,.tsx,.html,.vue,省去了配置其支持各种包含 js 代码文件的时间
    HTML CSS Support —— 让 html 标签上写 class 智能提示当前项目所支持的样式
    HTML Snippets —— html 快速自动补全
    Open in browser —— 浏览器快速打开
    Live Server —— 以内嵌服务器方式打开
    Chinese (Simplified) Language Pack for Visual Studio Code —— 中文语言包

    3.5.4 安装配置 git

    进入 git bash

    1. 配置用户名 git config --global user.name “longxi_ct” //(名字)

    2. 配置邮箱 git config --global user.email “447651097@qq.com” //(注册账号时用的邮箱)

    3.5.5 配置 ssh 免密登录

    ssh-keygen -t rsa -C "447651097@qq.com"
    
    • 1

    连续三次回车。

    在这里插入图片描述
    查看密钥

    cat ~/.ssh/id_rsa.pub
    
    • 1

    登录进入 gitee,在设置里面找到 SSH KEY 将.pub 文件的内容粘贴进去 使用 ssh -T git@gitee.com 测试是否成功即可
    在这里插入图片描述

    使用 ssh -T git@gitee.com 测试是否成功即可

    在这里插入图片描述

    3.5.6 新建码云git仓库

    在这里插入图片描述
    clone项目地址

    3.5.7 在iead里新建项目

    在这里插入图片描述
    选择GIT,粘贴刚才的clone地址
    在这里插入图片描述

    3.5.8 创建以下模块

    商品服务 product
    存储服务 ware
    订单服务 order
    优惠券服务 coupon
    用户服务 member
    每个模块导入web和openFeign

    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述

    在这里插入图片描述

    在这里插入图片描述

    3.5.9 修改工程配置文件

    从模块里复制出来一个pom.xml到工程目录下

    
    <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.0modelVersion>
        <groupId>com.longxi.gulimallgroupId>
        <artifactId>gulimallartifactId>
        <version>0.0.1-SNAPSHOTversion>
        <name>gulimall-warename>
        <description>聚合服务description>
        <properties>
            <java.version>1.8java.version>
            <spring-cloud.version>2021.0.3spring-cloud.version>
        properties>
        <packaging>pompackaging>
        <modules>
            <module>module>
            <module>gulimall-productmodule>
            <module>gulimall-waremodule>
            <module>gulimall-ordermodule>
            <module>gulimall-couponmodule>
            <module>gulimall-membermodule>
    
        modules>
    
    project>
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26

    刷新maven,添加总服务
    在这里插入图片描述

    在这里插入图片描述
    谷粒mall变成root

    3.5.10 配置忽略文件

    主服务.gitignore,子服务的全部删除

    target/
    pom.xml.tag
    pom.xml.releaseBackup
    pom.xml.versionsBackup
    pom.xml.next
    release.properties
    dependency-reduced-pom.xml
    buildNumber.properties
    .mvn/timing.properties
    # https://github.com/takari/maven-wrapper#usage-without-binary-jar
    .mvn/wrapper/maven-wrapper.jar
    
    **/mvnw
    **/mvnw.cmd
    **/mvn
    **/target/
    .idea
    **/.gitignore
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19

    3.5.11 有效代码,纳入版本控制

    在这里插入图片描述

    3.5.12 安装码云插件

    在这里插入图片描述
    在这里插入图片描述
    去掉代码检查,去掉TODO检查

    3.5.13 Commit and Push提交代码

    在这里插入图片描述

    3.5.14 代码已经提交

    在这里插入图片描述

    3.5.15 创建数据库

    商品数据库
    在这里插入图片描述

    数据库名含义
    gulimall_pms商品系统
    gulimall_oms订单系统
    gulimall_sms营销系统
    gulimall_ums用户系统
    gulimall_wms库存系统

    导入表,表结构文件自行下载

    https://gitee.com/longxi-ct/guilimall

    3.5.16 人人开源搭建后台管理项目

    3.5.16.1 克隆项目

    https://gitee.com/renrenio
    在这里插入图片描述

    reren-fast后端工程

     https://gitee.com/renrenio/renren-fast.git
    
    • 1

    reren-fast-vue前端工程

    https://gitee.com/renrenio/renren-fast-vue.git
    
    • 1

    3.5.16.2 reren-fast导入gulimall工程

    在这里插入图片描述
    加入pom.xml

        <modules>
            <module>module>
            <module>gulimall-productmodule>
            <module>gulimall-waremodule>
            <module>gulimall-ordermodule>
            <module>gulimall-couponmodule>
            <module>gulimall-membermodule>
            <module>renren-fastmodule>
    
        modules>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    3.5.16.3 创建【gulimall-admin】数据库,导入renren-fast的【mysql.sql】的表结构

    在这里插入图片描述

    3.5.16.4 修改【application-dev.yml】的数据库配置

    spring:
        datasource:
            type: com.alibaba.druid.pool.DruidDataSource
            druid:
                driver-class-name: com.mysql.cj.jdbc.Driver
                url: jdbc:mysql://xxx.xx.xx.xxx:3307/gulimall-admin?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
                username: root
                password: root
                initial-size: 10
                max-active: 100
                min-idle: 10
                max-wait: 60000
                pool-prepared-statements: true
                max-pool-prepared-statement-per-connection-size: 20
                time-between-eviction-runs-millis: 60000
                min-evictable-idle-time-millis: 300000
                #Oracle需要打开注释
                #validation-query: SELECT 1 FROM DUAL
                test-while-idle: true
                test-on-borrow: false
                test-on-return: false
                stat-view-servlet:
                    enabled: true
                    url-pattern: /druid/*
                    #login-username: admin
                    #login-password: admin
                filter:
                    stat:
                        log-slow-sql: true
                        slow-sql-millis: 1000
                        merge-sql: false
                    wall:
                        config:
                            multi-statement-allow: true
    
    
    ##多数据源的配置
    #dynamic:
    #  datasource:
    #    slave1:
    #      driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver
    #      url: jdbc:sqlserver://localhost:1433;DatabaseName=renren_security
    #      username: sa
    #      password: 123456
    #    slave2:
    #      driver-class-name: org.postgresql.Driver
    #      url: jdbc:postgresql://localhost:5432/renren_security
    #      username: renren
    #      password: 123456
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49

    3.5.16.5 启动项目

    在这里插入图片描述

    3.5.16.5 用Visual Studio Code 打开【renren-fast-Vue】项目

    3.5.16.6 安装node.js

    前端开发,少不了 node.js;
    Node.js 是一个基于 Chrome V8 引擎的 JavaScript 运行环境。 http://nodejs.cn/api/ 我们关注与 node.js 的 npm 功能就行;
    NPM 是随同 NodeJS 一起安装的包管理工具,JavaScript-NPM,Java-Maven;
    1)、官网下载安装 node.js,并使用 node -v 检查版本
    2)、配置 npm 使用淘宝镜像 npm config set registry http://registry.npm.taobao.org/
    3)、大家如果 npm install 安装依赖出现 chromedriver 之类问题,先在项目里运行下面命令 npm install chromedriver --chromedriver_cdnurl=http://cdn.npm.taobao.org/dist/chromedriver 然后再运行 npm install
    在这里插入图片描述
    用npm命令下载前端运行需要的组件

    npm install
    
    • 1

    如果下载爆红,退出vss code,重新启动即可
    在这里插入图片描述
    下载依赖的版本在【package.json】都有描述,下载完的依赖会在【node_modules】里显示

    3.5.16.7 启动项目

    npm run dev
    
    • 1

    在这里插入图片描述

    3.5.16.8 启动成功

    在这里插入图片描述
    在这里插入图片描述
    成功登录

    3.5.17 逆向工程搭建和使用

    3.5.17.1 下载人人开源代码生成器

    在这里插入图片描述

    https://gitee.com/renrenio/renren-generator.git
    把工程导入到谷粒商城,复制,粘贴

    修改pom.xml文件

        <modules>
            <module>module>
            <module>gulimall-productmodule>
            <module>gulimall-waremodule>
            <module>gulimall-ordermodule>
            <module>gulimall-couponmodule>
            <module>gulimall-membermodule>
            <module>renren-fastmodule>
            <module>renren-generatormodule>
        modules>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    3.5.17.2 修改application.yml的数据库配置

    修改generator.properties,设置生成sql的属性

    #\u4EE3\u7801\u751F\u6210\u5668\uFF0C\u914D\u7F6E\u4FE1\u606F
    # 主目录
    mainPath=com.longxi
    # 包名
    package=com.longxi.gulimall
    # 模块
    moduleName=product
    # 作者
    author=longxi
    #Email
    email=447651097@qq.com
    # 表的前缀
    tablePrefix=pms_
    
    #\u7C7B\u578B\u8F6C\u6362\uFF0C\u914D\u7F6E\u4FE1\u606F
    tinyint=Integer
    smallint=Integer
    mediumint=Integer
    int=Integer
    integer=Integer
    bigint=Long
    float=Float
    double=Double
    decimal=BigDecimal
    bit=Boolean
    
    char=String
    varchar=String
    tinytext=String
    text=String
    mediumtext=String
    longtext=String
    
    
    date=Date
    datetime=Date
    timestamp=Date
    
    NUMBER=Integer
    INT=Integer
    INTEGER=Integer
    BINARY_INTEGER=Integer
    LONG=String
    FLOAT=Float
    BINARY_FLOAT=Float
    DOUBLE=Double
    BINARY_DOUBLE=Double
    DECIMAL=BigDecimal
    CHAR=String
    VARCHAR=String
    VARCHAR2=String
    NVARCHAR=String
    NVARCHAR2=String
    CLOB=String
    BLOB=String
    DATE=Date
    DATETIME=Date
    TIMESTAMP=Date
    TIMESTAMP(6)=Date
    
    int8=Long
    int4=Integer
    int2=Integer
    numeric=BigDecimal
    
    nvarchar=String
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66

    启动项目

    访问启动后的地址

    http://localhost/80

    选中所有表,进行代码生成
    在这里插入图片描述
    解压后导入,工程里。main文件夹直接覆盖,删除src/main/resources/src/views/modules/product目录下的前端代码,现在用不上。
    在这里插入图片描述

    3.5.17.3 创建gulimall-common,导入共用依赖的文件

    在这里插入图片描述

    其他服务依赖gulimall-common项目

            <dependency>
                <groupId>com.longxi.gulimallgroupId>
                <artifactId>gulimall-commonartifactId>
                <version>0.0.1-SNAPSHOTversion>
            dependency>
    
    • 1
    • 2
    • 3
    • 4
    • 5

    修改common的pom.xml文件

    
    <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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <parent>
            <artifactId>gulimallartifactId>
            <groupId>com.longxi.gulimallgroupId>
            <version>0.0.1-SNAPSHOTversion>
        parent>
        <modelVersion>4.0.0modelVersion>
    
        <artifactId>gulimall-commonartifactId>
        <description>每一个微服务的共同依赖description>
    
        <properties>
            <maven.compiler.source>11maven.compiler.source>
            <maven.compiler.target>11maven.compiler.target>
        properties>
    
        <dependencies>
            <dependency>
                <groupId>com.baomidougroupId>
                <artifactId>mybatis-plus-boot-starterartifactId>
                <version>3.2.0version>
            dependency>
            <dependency>
                <groupId>org.projectlombokgroupId>
                <artifactId>lombokartifactId>
                <version>1.18.8version>
            dependency>
            <dependency>
                <groupId>org.apache.httpcomponentsgroupId>
                <artifactId>httpcoreartifactId>
                <version>4.4.13version>
            dependency>
            <dependency>
                <groupId>commons-langgroupId>
                <artifactId>commons-langartifactId>
                <version>2.6version>
            dependency>
        dependencies>
    
    project>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43

    从renren-fast/src/main/java/io/renren/common/utils复制所需要的共通类

    从renren-fast/src/main/java/io/renren/common/xss复制所需要的共通类在这里插入图片描述

    因为RequiresPermissions报错,所以调整renren-generator工程的Controller.java.vm模板,
    注释掉

        //@RequiresPermissions("${moduleName}:${pathName}:list")
        //import org.apache.shiro.authz.annotation.RequiresPermissions;
    
    • 1
    • 2

    在这里插入图片描述

    在这里插入图片描述

    重新启动工程,生成代码,重新导入

    3.5.17.4 整合mybaits-plus

    导入依赖

            <dependency>
                <groupId>com.baomidougroupId>
                <artifactId>mybatis-plus-boot-starterartifactId>
                <version>3.2.0version>
            dependency>
    
    • 1
    • 2
    • 3
    • 4
    • 5

    导入驱动包

            
            <dependency>
                <groupId>mysqlgroupId>
                <artifactId>mysql-connector-javaartifactId>
                <version>8.0.17version>
            dependency>
            
            <dependency>
                <groupId>javax.servletgroupId>
                <artifactId>servlet-apiartifactId>
                <version>2.5version>
                <scope>providedscope>
            dependency>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13

    servlet-api一般tomcat都会自带,所以把scope调整成provided,打包的时候就不用带上了

    删除
    gulimall-common/src/main/java/com/longxi/common/xss/XssFilter.java
    gulimall-common/src/main/java/com/longxi/common/xss/XssHttpServletRequestWrapper.java,之后用spring-security
    从renren-fast工程,导入renren-fast/src/main/java/io/renren/common/exception/RRExceptionHandler.java

    3.5.17.5 配置数据源。在产品服务gulimall-product下,新建src/main/resources/application.yml文件

    spring:
      datasource:
        username: root
        password: root
        url: jdbc:mysql://xxx.xx.xx.xxx:3307/gulimall_pms?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai
        driver-class-name: com.mysql.cj.jdbc.Driver
    mybatis-plus:
      mapper-locations: classpath:/mapper/**/*.xml
      # 主键自增
      global-config:
        db-config:
          id-type: auto
    server:
      port: 10000
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14

    classpath:扫描自己项目下的
    classpath*:扫描所有项目下的

    3.5.17.6 同样的方法,为其他服务生成代码

    3.5.17.6.1 优惠服务gulimall-coupon:修改renren-generator配置文件

    generator.properties

    # 主目录
    mainPath=com.longxi
    # 包名
    package=com.longxi.gulimall
    # 模块
    moduleName=coupon
    # 作者
    author=longxi
    #Email
    email=447651097@qq.com
    # 表的前缀
    tablePrefix=sms_
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12

    application.yml

    # mysql
    spring:
      datasource:
        type: com.alibaba.druid.pool.DruidDataSource
        #MySQL配置
        driverClassName: com.mysql.cj.jdbc.Driver
        url: jdbc:mysql://xxx.xx.xx.xxx:3307/gulimall_sms?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai
        username: root
        password: root
        mybatis-plus:
      mapper-locations: classpath:/mapper/**/*.xml
      # 主键自增
      global-config:
        db-config:
          id-type: auto
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16

    生成代码并导入到工程
    新建gulimall-coupon服务的application.yml

    spring:
      datasource:
        username: root
        password: root
        url: jdbc:mysql://xxx:3307/gulimall_sms?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai
        driver-class-name: com.mysql.cj.jdbc.Driver
    mybatis-plus:
      mapper-locations: classpath:/mapper/**/*.xml
      # 主键自增
      global-config:
        db-config:
          id-type: auto
    server:
      port: 7000
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    3.5.17.6.2 会员服务gulimall-member:修改renren-generator配置文件

    generator.properties

    # 主目录
    mainPath=com.longxi
    # 包名
    package=com.longxi.gulimall
    # 模块
    moduleName=menber
    # 作者
    author=longxi
    #Email
    email=447651097@qq.com
    # 表的前缀
    tablePrefix=ums_
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12

    application.yml

    spring:
      datasource:
        type: com.alibaba.druid.pool.DruidDataSource
        #MySQL配置
        driverClassName: com.mysql.cj.jdbc.Driver
        url: jdbc:mysql://xxx.xx.xx.xxx:3307/gulimall_ums?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai
        username: root
        password: root
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    生成代码并导入到工程
    新建gulimall-member服务的application.yml

    spring:
      datasource:
        username: root
        password: root
        url: jdbc:mysql://xxx:3307/gulimall_ums?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai
        driver-class-name: com.mysql.cj.jdbc.Driver
    mybatis-plus:
      mapper-locations: classpath:/mapper/**/*.xml
      # 主键自增
      global-config:
        db-config:
          id-type: auto
    server:
      port: 8000
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14

    生成代码并替换

    3.5.17.6.3 订单服务gulimall-order:修改renren-generator配置文件
    # 主目录
    mainPath=com.longxi
    # 包名
    package=com.longxi.gulimall
    # 模块
    moduleName=order
    # 作者
    author=longxi
    #Email
    email=447651097@qq.com
    # 表的前缀
    tablePrefix=oms_
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12

    application.yml

    # mysql
    spring:
      datasource:
        type: com.alibaba.druid.pool.DruidDataSource
        #MySQL配置
        driverClassName: com.mysql.cj.jdbc.Driver
        url: jdbc:mysql://xxx:3307/gulimall_oms?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai
        username: root
        password: root
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    生成代码并导入到工程
    新建gulimall-order服务的application.yml

    spring:
      datasource:
        username: root
        password: root
        url: jdbc:mysql://xxx:3307/gulimall_oms?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai
        driver-class-name: com.mysql.cj.jdbc.Driver
    mybatis-plus:
      mapper-locations: classpath:/mapper/**/*.xml
      # 主键自增
      global-config:
        db-config:
          id-type: auto
    server:
      port: 9000
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    3.5.17.6.4 库存服务gulimall-ware:修改renren-generator配置文件
    # 主目录
    mainPath=com.longxi
    # 包名
    package=com.longxi.gulimall
    # 模块
    moduleName=ware
    # 作者
    author=longxi
    #Email
    email=447651097@qq.com
    # 表的前缀
    tablePrefix=wms_
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12

    application.yml

    spring:
      datasource:
        type: com.alibaba.druid.pool.DruidDataSource
        #MySQL配置
        driverClassName: com.mysql.cj.jdbc.Driver
        url: jdbc:mysql://xxx:3307/gulimall_wms?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai
        username: root
        password: root
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    生成代码并导入到工程
    新建gulimall-ware服务的application.yml

    spring:
      datasource:
        username: root
        password: root
        url: jdbc:mysql://xxx:3307/gulimall_wms?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai
        driver-class-name: com.mysql.cj.jdbc.Driver
    mybatis-plus:
      mapper-locations: classpath:/mapper/**/*.xml
      # 主键自增
      global-config:
        db-config:
          id-type: auto
    server:
      port: 11000
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    3.5.17.6.5 启动成功

    在这里插入图片描述

  • 相关阅读:
    chatGPT免费AI交互产品的应用
    MySQL索引失效场景以及解决方案
    AWS攻略——一文看懂AWS IAM设计和使用
    【附源码】计算机毕业设计SSM税务综合信息平台
    计算点云每个点的梯度(附open3d python代码)
    基于.Net项目实施管理系统设计与实现
    JUC并发编程--------基础篇
    iPhone苹果15手机怎么取消订阅付费的项目?
    记一次manjaro-i3系统sogoupinying候选词无法正常显示中文(变方框了)问题解决方案
    套接字sock实例
  • 原文地址:https://blog.csdn.net/weixin_42620326/article/details/125984833