当前位置:   article > 正文

【谷粒商城开发笔记一】初步搭建环境_谷粒商城docker安装环境搭建

谷粒商城docker安装环境搭建

一、环境搭建

一种设计风格–微服务

微服务是指把一个架构复杂庞大的软件拆分成一个个功能模块,或者说一个个小服务,采用轻量级通信机制,一般是HTTP API

弹幕大多数说电脑至少需要16G内存

1.1 安装Linux虚拟机

virtualBox6.0是开源的去官网直接下载即可,但是要注意开启CPU虚拟化才能开始安装

首先确认自己电脑是否已经开启了CPU虚拟化,打开任务管理器->性能->CPU,观察虚拟化字段是否已启动

下载完以后要在此处修改虚拟机安装路径
在这里插入图片描述

安装镜像Linux Vagrant2.25

下载完vagrant以后要设置环境变量
在这里插入图片描述

1)利用镜像安装centos7

vagrant init centos7 https://mirrors.ustc.edu.cn/centos-cloud/centos/7/vagrant/x86_64/images/CentOS-7.box
  • 1

2)开始下载

遇见如下报错

 Could not create a directory 'D:\xxx\vmFile\centos-7-1-1.x86_64_1716951173879_75099' to save the settings file (VERR_ACCESS_DENIED)
  • 1

最后重新设置了virtualBox全局设定路径才行

每次开机使用

vagrant up
vagrant ssh
  • 1
  • 2

为虚拟机设置静态ip
具体操作如下
首先,本机cmd执行ipconfig
找到VirtualBox虚拟网卡网址
进入VagrantFile文件中,找到如下行

# config.vm.network "private_network", ip: "192.168.xx.10"
  • 1

将上面改为virtualbox同网段,并取消注释#

》然后,重新启动虚拟机
vagrant reload

》最后,登录虚拟机互相ping

# windows
 ipconfig
  • 1
  • 2
#linux
ip addr
  • 1
  • 2

1.2 安装docker

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

docker下载地址
安装前先卸载
在这里插入图片描述
安装依赖包
sudo yum install -y yum-utils device-mapper-persistent-data lvm2

sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

安装docker
sudo yum install docker-ce docker-ce-cli containerd.io
添加镜像

yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
  • 1

启动docker

sudo systemctl start docker

开机自启

sudo systemctl enable docker

添加docker镜像加速器

sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-‘EOF’
{
“registry-mirrors”: [“https://aszg8dso.mirror.aliyuncs.com”]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker

1.3 docker安装MySQL

sudo docker pull mysql:5.7
在这里插入图片描述
docker run -p 3306:3306 --name mysql
-v /mydata/mysql/log:/var/log/mysql
-v /mydata/mysql/data:/var/lib/mysql
-v /mydata/mysql/conf:/etc/mysql
-e MYSQL_ROOT_PASSWORD=root
-d mysql:5.7
在这里插入图片描述

每次docker run就会启动一个容器

进入某ID容器
docker exec -it mysql /bin/bash
查看正在运行中的容器
docker ps

在这里插入图片描述
[client]
default-character-set=utf8

[mysql]
default-character-set=utf8

[mysqld]
init_connect=‘SET collation_connection = utf8_unicode_ci’
init_connect=‘SET NAMES utf8’
character-set-server=utf8
collation-server=utf8_unicode_ci
skip-character-set-client-handshake
skip-name-resolve

重启服务
docker restart mysql

开机自动启动mysql
docker update mysql --restart=always

1.4 docker安装redis

docker pull redis:5.0.5

在这里插入图片描述

mkdir -p /mydata/redis/conf
touch /mydata/redis/conf/redis.conf

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

配置缓存持久化
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

二、创建项目注意事项

2.1 需要注意springboot的版本

如果更改之后openfeign依赖找不到,在该依赖下面加上版本
找不到2.1.8版本的,先用新版本创建,然后手动更改

2.2 安装node.js

亲测 node 14.15.0版本可以跑起来
10.24.1在执行npm install会报错,换了14.21.3
在这里插入图片描述
npm config set registry http://registry.npm.taobao.org/

重启vscode在控制台执行
npm install
会在当前路径下多出文件夹node_modules
在这里插入图片描述
重新执行install要执行
npm cache clean --force
在cmd中执行最终成功
在这里插入图片描述

运行起来fast vue
npm run dev
在这里插入图片描述
renren generator配置
在pom中纳管该模块
在这里插入图片描述

修改yml文件
在这里插入图片描述
修改proprities文件
在这里插入图片描述

修改controller生成模板中的代码
在这里插入图片描述

运行generator下面的主函数,进入下页面
逆向生成所有表
在这里插入图片描述

三、代码部分

3.1 @Data

加了这个注解就不需要get set方法,依赖lombok

3.2 导入Common pom依赖

导入mybatis-plus maven坐标

导入mysql驱动要关注版本适配,mysql版本 vs 驱动版本
在这里插入图片描述
在这里插入图片描述

3.2 maven配置中的scope字段

见3.2中描述

3.3 @MapperScan

@MapperScan(“com.atguigu.gulimall.product.dao”)
告诉主函数mapper.java文件在哪里
需要在yml文件中配置xml文件路径
在这里插入图片描述

3.4 @TableId

标识主键属性,需要在yml文件中配置自增逐渐

3.5 springboot版本引发的@test爆红

import org.junit.jupiter.api.Test 用在Spring Boot 2.2.X以后
import org.junit.Test用在2.2.x之前

3.7 遇见报错

nested exception is io.seata.common.exception.NotSupportYetException: not support register type: null,在本链接得到启发
具体报错为

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'globalTransactionScanner' defined in class path resource [com/alibaba/cloud/seata/GlobalTransactionAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [io.seata.spring.annotation.GlobalTransactionScanner]: Factory method 'globalTransactionScanner' threw exception; nested exception is io.seata.common.exception.NotSupportYetException: not support register type: null
	at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:627) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:456) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1321) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1160) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:204) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.context.support.PostProcessorRegistrationDelegate.registerBeanPostProcessors(PostProcessorRegistrationDelegate.java:228) ~[spring-context-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:721) ~[spring-context-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:534) ~[spring-context-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141) ~[spring-boot-2.1.8.RELEASE.jar:2.1.8.RELEASE]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:744) [spring-boot-2.1.8.RELEASE.jar:2.1.8.RELEASE]
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:391) [spring-boot-2.1.8.RELEASE.jar:2.1.8.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:312) [spring-boot-2.1.8.RELEASE.jar:2.1.8.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215) [spring-boot-2.1.8.RELEASE.jar:2.1.8.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1204) [spring-boot-2.1.8.RELEASE.jar:2.1.8.RELEASE]
	at com.atguigu.gulimall.order.GulimallOrderApplication.main(GulimallOrderApplication.java:10) [classes/:na]
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [io.seata.spring.annotation.GlobalTransactionScanner]: Factory method 'globalTransactionScanner' threw exception; nested exception is io.seata.common.exception.NotSupportYetException: not support register type: null
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:622) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	... 19 common frames omitted
Caused by: io.seata.common.exception.NotSupportYetException: not support register type: null
	at io.seata.config.ConfigurationFactory.buildConfiguration(ConfigurationFactory.java:80) ~[seata-all-0.7.1.jar:0.7.1]
	at io.seata.config.ConfigurationFactory.getInstance(ConfigurationFactory.java:65) ~[seata-all-0.7.1.jar:0.7.1]
	at io.seata.spring.annotation.GlobalTransactionScanner.<init>(GlobalTransactionScanner.java:81) ~[seata-all-0.7.1.jar:0.7.1]
	at io.seata.spring.annotation.GlobalTransactionScanner.<init>(GlobalTransactionScanner.java:124) ~[seata-all-0.7.1.jar:0.7.1]
	at io.seata.spring.annotation.GlobalTransactionScanner.<init>(GlobalTransactionScanner.java:113) ~[seata-all-0.7.1.jar:0.7.1]
	at com.alibaba.cloud.seata.GlobalTransactionAutoConfiguration.globalTransactionScanner(GlobalTransactionAutoConfiguration.java:58) ~[spring-cloud-alibaba-seata-2.1.0.RELEASE.jar:2.1.0.RELEASE]
	at com.alibaba.cloud.seata.GlobalTransactionAutoConfiguration$$EnhancerBySpringCGLIB$$e99a3ce9.CGLIB$globalTransactionScanner$0(<generated>) ~[spring-cloud-alibaba-seata-2.1.0.RELEASE.jar:2.1.0.RELEASE]
	at com.alibaba.cloud.seata.GlobalTransactionAutoConfiguration$$EnhancerBySpringCGLIB$$e99a3ce9$$FastClassBySpringCGLIB$$22db3d63.invoke(<generated>) ~[spring-cloud-alibaba-seata-2.1.0.RELEASE.jar:2.1.0.RELEASE]
	at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244) ~[spring-core-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:363) ~[spring-context-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at com.alibaba.cloud.seata.GlobalTransactionAutoConfiguration$$EnhancerBySpringCGLIB$$e99a3ce9.globalTransactionScanner(<generated>) ~[spring-cloud-alibaba-seata-2.1.0.RELEASE.jar:2.1.0.RELEASE]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_201]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_201]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_201]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_201]
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	... 20 common frames omitted
Caused by: java.lang.IllegalArgumentException: illegal type:null
	at io.seata.config.ConfigType.getType(ConfigType.java:62) ~[seata-all-0.7.1.jar:0.7.1]
	at io.seata.config.ConfigurationFactory.buildConfiguration(ConfigurationFactory.java:78) ~[seata-all-0.7.1.jar:0.7.1]
	... 35 common frames omitted


Process finished with exit code 1

  • 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

删除maven依赖
在这里插入图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/872818
推荐阅读
相关标签
  

闽ICP备14008679号