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應用


分享到:


相關文章: