程序员的资源宝库

网站首页 > gitee 正文

五、创建项目微服务--谷粒商城

sanyeah 2024-04-13 16:16:00 gitee 4 ℃ 0 评论

1)从gitee初始化一个项目

登录码云,新建仓库

创建完成之后,复制项目地址

 

打开idea,选择file,new->project from version Control

 输入地址

在克隆的时候,idea会弹出输入码云用户名密码的窗口,是码云的,不是Git的。
这个项目作为总项目,接下来,会在这个项目下面创建各个微服务项目。

 

 

2)创建微服务项目
微服务项目:gulimall

商品服务:mall-product
仓储服务: mall-ware

订单服务:mall-order

优惠券服务: mall-coupon

用户服务:mall-member
微服务项目的共同点:

          依赖:web、openfeign
          每个服务的包名都是com.atguigu.gulimall.xxx(producnt/order/ware/coupon/member)
          模块名:gulimall-xxx
分别创建出以下模块

gulimall(pox文件)

<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.stu.gulimall</groupId>
    <artifactId>gulimall</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>pom</packaging>

    <modules>
        <module>mall-coupon</module>
        <module>mall-member</module>
        <module>mall-order</module>
        <module>mall-product</module>
        <module>mall-ware</module>
    </modules>
    <name>gulimall</name>
    <description>聚合服务</description>

    <!--  这里的属性会被子模块继承  -->
    <properties>
        <java.version>1.8</java.version>
        <spring-cloud.version>Hoxton.SR12</spring-cloud.version>
        <spring.boot.version>2.3.12.RELEASE</spring.boot.version>
    </properties>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>${spring.boot.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <!--  这里的依赖会被子模块继承  -->
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-openfeign</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

mall-coupon(pox文件)

<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>gulimall</artifactId>
        <groupId>com.stu.gulimall</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <name>gulimall-coupon</name>
    <artifactId>mall-coupon</artifactId>
    <groupId>com.stu.gulimall</groupId>
    <version>1.0-SNAPSHOT</version>
    <description>优惠券服务</description>


    <properties>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
    </properties>

</project>

mall-member(pox文件)

<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>gulimall</artifactId>
        <groupId>com.stu.gulimall</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>mall-member</artifactId>
    <name>mall-member</name>
    <groupId>com.stu.gulimall</groupId>
    <version>1.0-SNAPSHOT</version>
    <description>用户服务</description>

    <properties>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
    </properties>

</project>

mall-order(pox文件)

<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>gulimall</artifactId>
        <groupId>com.stu.gulimall</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>mall-order</artifactId>
    <name>mall-order</name>
    <groupId>com.stu.gulimall</groupId>
    <version>1.0-SNAPSHOT</version>
    <description>订单服务</description>

    <properties>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
    </properties>

</project>

mall-product(pox文件)

<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>gulimall</artifactId>
        <groupId>com.stu.gulimall</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>mall-product</artifactId>
    <name>mall-product</name>
    <groupId>com.stu.gulimall</groupId>
    <version>1.0-SNAPSHOT</version>
    <description>商品服务</description>

    <properties>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
    </properties>

</project>

mall-ware(pox文件)

<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>gulimall</artifactId>
        <groupId>com.stu.gulimall</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>mall-ware</artifactId>
    <name>mall-ware</name>
    <groupId>com.stu.gulimall</groupId>
    <version>1.0-SNAPSHOT</version>
    <description>仓储服务</description>

    <properties>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
    </properties>

</project>

 

 

修改总服务的gitignore文件:
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



**/target/

.idea

然后在git的localchanges的地方,右键default changelist,选择add to vcs,将整理好的文件纳入版本控制

但这些文件如果想上传到码云,还需要下载gitee插件
在idea的file菜单下找到settings,在plugin中下载gitee插件

在控制台的Git页中,右键DefaultChanges,点击cmmit file,即可提交,但这是提交到本地git

 

 点击commit ,在出现的界面右下角,选择commit的下拉框,选择commit and push,可以直接将项目上传到码云

 提交完之后,打开码云即可查看到刚才提交的项目。
如果当时没有选择commit and push,选择了commit,也可以直接在文件目录下右键,选择git bash ,输入命令git push来提交代码到码云

3)数据库初始化 

此步骤需要安装powerdesigner工具,打开数据库设计的表结构。

安装转载:https://www.cnblogs.com/jepson6669/p/8921043.html

文件下载:http://forspeed.onlinedown.net/down/powerdesigner1029.zip

 

根据数据库的设计,我们可以根据逆向工程,快速创建出各个模块的增删改查代码,来简化开发。
每个模块对应一个数据库,表的字段和含义暂不做详解,等用到时再详细解释和介绍。
该数据库表的设计最大的特点是就是:表的设计再复杂,表之间没有外键关系,因为在电商项目里面,数据量超大,做外键关联是一个非常耗费数据库性能的操作。假设每张表都有几十万甚至几百万的数据,那么每次插入删除一条数据,数据库都需要对外键进行检查来保持自己的一致性。
具体的表结构语句也放在网盘中,可以根据语句直接创建出数据库表。

    • 启动虚拟机
      可以使用virtualbox,右键启动虚拟机;
      也可以使用cmd命令:vagrant up 快速启动虚拟机。
    • 需要启动容器后才能连接mysql,
      //其中的redis和mysql为前面查出的容器的name值
      docker update redis --restart=always
      docker update mysql --restart=always
    • 使用mysql客户端连接mysql
      主机地址:192.168.56.10,用户名root,密码root。
    • 然后在可视化工具sqlyog上分别创建所有模块的数据库,使用字符集utf8mb4,这个字符集可以兼容utf8

       

       

      然后将对应的每个数据库的表文件打开复制粘贴,创建表结构。

 

通过人人开源生成代码

参考:https://gitee.com/renrenio

后台管理系统:https://gitee.com/renrenio/renren-fast

后台管理前端:https://gitee.com/renrenio/renren-fast-vue

代码生成器:https://gitee.com/renrenio/renren-generator

 

 

后端:导入下载的代码后,在聚合模块加入该模块,在application-dev.yml中修改对应mysql配置:

driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://192.168.56.10:3306/gulimall_admin?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&useSSL=false
username: root
password: root

 

项目启动时报错:

com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure

解决方法(转载):https://blog.csdn.net/lvoelife/article/details/129284611?spm=1001.2101.3001.6650.1&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7ERate-1-129284611-blog-81065520.235%5Ev32%5Epc_relevant_increate_t0_download_v2&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7ERate-1-129284611-blog-81065520.235%5Ev32%5Epc_relevant_increate_t0_download_v2&utm_relevant_index=2

或者:https://blog.csdn.net/qq_27471405/article/details/80921846?spm=1001.2101.3001.6661.1&utm_medium=distribute.pc_relevant_t0.none-task-blog-2%7Edefault%7ECTRLIST%7ERate-1-80921846-blog-129225733.235%5Ev32%5Epc_relevant_increate_t0_download_v2&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-2%7Edefault%7ECTRLIST%7ERate-1-80921846-blog-129225733.235%5Ev32%5Epc_relevant_increate_t0_download_v2&utm_relevant_index=1

 

 

 

 

 

前端引入人人开源前端项目时出现错误:

建立工作区,放入代码,打开终端运行npm install 

npm ERR! node-sass@4.13.1 postinstall: `node scripts/build.js`

 

 

npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! chromedriver@2.27.2 install: `node install.js` np:

1. 删除node_modules文件夹
2. 修改项目文件 package.json 中的 saas 版本(不用太高也不能太低)
   "node-sass": "4.13.1",
  
"sass-loader": "7.3.1", 3. 执行以下四条命令
  npm install chromedriver
--chromedriver_cdnurl=http://cdn.npm.taobao.org/dist/chromedriver   npm i node-sass --sass_binary_site=https://npm.taobao.org/mirrors/node-sass/   npm install   npm run dev

 

 

 

导入代码生成器,更改数据库配置,运行进入生成器页面,生成代码

 

然后替换整合便可,整合时出现了一些maven问题,maven问题大多数都是版本不一,教程给的多多少少有点问题(也可能时我下载的不对),需要自己去一个一个的看一下<version>0.0.1-SNAPSHOT</version>,版本最好把所有的统一,我得到的教程里的不一样,后面便自己改了

 

到此,谷粒商城创建项目完成。

 

Tags:

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表