springCloud微服务之商品微服务注册

这节其实和用户微服务注册有很多的共同点,可以参照用户微服务将商品微服务做出来,这里只讲需要修改的地方

1、创建商品数据库和表结构

create schema cloud_good collate utf8mb4_0900_ai_ci;
create table c_good
(
 id char(32) not null,
 good_name varchar(50) null,
 good_stock int null comment '库存',
 good_price double not null comment '价格',
 create_date datetime not null,
 create_by char(32) not null,
 update_date datetime not null,
 update_by char(32) not null,
 constraint good_id_uindex
 unique (id)
)
comment '商品';
alter table c_good
 add primary key (id);

2、其他操作和用户微服务类似,只是命名不同,完整结构如下图

springCloud微服务之商品微服务注册

3、修改配置文件

修改application.yml里面的端口号和应用名

server:
 port: 8883
......
url: jdbc:mysql://apg-server:3306/cloud_good?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&failOverReadOnly=false&serverTimezone=Asia/Shanghai
......
 application:
 name: cloud-good

修改log4j.properties日志文件名

log4j.appender.R.File=good.log

4、启动商品微服务并测试

springCloud微服务之商品微服务注册

用postman测试保存方法

springCloud微服务之商品微服务注册

测试查询方法

用刚刚保存成功的id进行查询

springCloud微服务之商品微服务注册

5、文章源码地址

关注+转发后私信我发源码地址

至此三个基本的业务微服务就都创建完了,后面开始微服务互相调用的编码,在调用之前先弄一个网关进行微服务调用请求的处理,以及后续各种跟微服务相关的组件都会进行集成,搞一个全面的微服务架构的web应用


分享到:


相關文章: