Lazy loaded image
SpringCloud
Nacos
Words 621Read Time 2 min
2025-4-25
2025-4-26
type
status
date
slug
summary
tags
category
icon
password

一、安装

step1:
step2:
切换到 bin 目录下,并执行以下命令
访问localhost:8848/nacos即可

二、注册中心

2.1 服务注册

1、先在父项目中引入依赖
2、分别在子项目的配置文件中加入以下
3、启动项目,之后注册成功会在服务管理里面看到如下
notion image
4、我们也可以去启动几份项目,搞下集群
notion image
notion image

2.2 服务发现

1、在启动类上表注解
2、去做下测试

2.3 远程调用

1、基本流程
notion image
2、下单场景
notion image
3、远程调用实现
建一个model模块,存放公共的实体类
notion image
之后在service的pom文件里面导入model依赖
Product模块如下
ProductController代码
ProductServiceImpl代码
Oder模块如下
OrderController代码
OrderServiceConfig代码
OrderServiceImpl代码
最后我们去请求
notion image
notion image
如果我们现在停掉了product的9000端口的应用,order应用去请求9001端口的应用,日志打印信息如下

2.4负载均衡

上一篇
MyBatis
下一篇
好用的工具网站

Comments
Loading...