首页 > 其他分享 >五、创建项目微服务--谷粒商城

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

时间:2023-04-30 15:56:24浏览次数:44  
标签:npm -- stu mall SNAPSHOT 谷粒 gulimall com 商城

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! [email protected] postinstall: `node scripts/build.js`

 

 

npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! [email protected] 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

 

 

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

 

标签:npm,--,stu,mall,SNAPSHOT,谷粒,gulimall,com,商城
From: https://www.cnblogs.com/ai377377/p/17365168.html

相关文章

  • Windows Docker 配置国内镜像源的两种方法
    更新时间2023.04.30版本号:23.0.5通过Docker-Desktop界面操作和修改daemon.json两种方法配置国内镜像源方法一:通过Docker-Desktop配置1.点击设置2.选择DockerEngine3.添加以下源地址"registry-mirrors":["https://docker.mirrors.ustc.edu.cn","https:/......
  • OOP4-6习题心得体会
    面向程序对象设计前言:1.相比于之前的题目,题目集4主要是在一些基本的题目类型,除去第一道题目,其他题目难度均比之前要小,包括字符串的排序,重复数据问题,以及java中Date类的使用,当然重中之重的是第一题的菜单题,不过由于个人的轻视以及懒导致并没有去做这一道题,直接导致了零......
  • 软考高项(信息系统项目管理师)—— 第 1 章 信息化发展——信息与信息化
    第1章信息化发展——信息与信息化一、概念 信息:information是物质、能量及其属性的标识的集合,是确定性的增加。它以物质介质为载体,传递和反映世界各种事物存在方式、运动状态等的表征。信息不是物质,也不是能力,它以一种普遍形式,表达物质运动规律,在客观世界中大量存在、产生......
  • 静态数码显示管显示
    先看原理图上面的led灯(也就是P2)来控制灯的选择(因为只能选择一个)控制灯的选择并不需要8个输入口来控制用个三八译码器即可代替上图极为138译码器用P2的2,3,4来输入,输入的数字对应的10进制数代表选择的led灯编号-1注意这里的顺序是4,3,2,也就是倒着来组成的然后选择......
  • 外设驱动库开发笔记53:MAX31856热偶变送器驱动
      在我们的产品中经常有需要温度检测的地方,而热电偶温度检测电路是我们常用的。热电偶温度检测的方法很多,有时出于简单方便的考虑我们会选择热偶温度变送器来实现,这一篇我们就来讨论使用MAX31856热电偶温度变送器实现温度的检测。1、功能概述  MAX31856可以对任何类型热电偶......
  • 万能修改串号imei软件技术原理
    在智能手机用户中,有一些人因为特定需求需要修改手机串号,例如解锁手机、绕过应用程序检测等。而万能修改串号IMEI软件成为了其中的一种解决方案。那么,这种技术的原理是什么呢?首先,我们需要了解万能修改串号IMEI软件的基本原理。IMEI是手机的唯一标识符,由15位数字组成。当手机......
  • 关于uniapp表单验证(uview)的坑
    uniapp在验证表单出现this.$refs.uForm.setRules(this.rules)ErrorinonReadyhook:"TypeErr的错误。在webh5在上,就会容易错误,语句比较严格。出现this.$refs.uForm.setRules(this.rules)ErrorinonReadyhook:"TypeErr的的原因是在onReady写两条初始化验证onReady()......
  • 10-react不同层级的组件之间的数据传递数据 createContext 上下文
    //组件传值props接收传递过来的数据importReactDomfrom"react-dom"import{createContext,Component}from"react"//createContextisuseedtocreateacontextbojectionfromcontextproperties//返回一个对象//Provider提供状态Consumer使用状态......
  • CS144 计算机网络 Lab3:TCP Sender
    前言在Lab2中我们实现了TCPReceiver,负责在收到报文段之后将数据写入重组器中,并回复给发送方确认应答号。在Lab3中,我们将实现TCP连接的另一个端点——发送方,负责读取ByteStream(由发送方上层应用程序创建并写入数据),并将字节流转换为报文段发送给接收方。代码实现TCPSe......
  • 差分约束
    差分约束系统用于求解一组特殊的N元一次不等式组.它包含了N个变量x1~xn和M个约束条件,其中每个约束条件形如:\(x_i\leqslantx_j+c_k\)(最短路),\(x_i\geqslantx_j+c_k\)(最长路)约束条件\(x_i\leqslantx_j+c_k\),可转化为一条有向边\(j\stackr......