当前位置:网站首页>Nacos中使用ribbon
Nacos中使用ribbon
2022-07-18 02:43:00 【胡尚】
- 我们引入了
nacos-discovery的依赖
<!--nacos的服务注册与发现依赖-->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
它会自动引入ribbon的依赖,不需要我们在手动引入
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-lE2z9fV4-1658024683983)(E:\Java笔记\image\springcloud_alibaba\image-20220608124603050.png)]](/img/85/ee894d09479c8bae2f85c784a65a6a.png)
- 我们如果要使用只需要添加
@LoadBalanced注解
@Configuration
public class RestConfig {
@Bean
@LoadBalanced
public RestTemplate restTemplate(RestTemplateBuilder builder){
RestTemplate restTemplate = builder.build();
return restTemplate;
}
}
- 在controller层调用的时候就直接使用服务名来进行调用
@RestController
@RequestMapping("/order")
public class OrderController {
// 注入RestTemplate对象
@Autowired
private RestTemplate restTemplate;
@RequestMapping("/add")
public String add(){
// 使用服务名进行调用
String message = restTemplate.getForObject("http://stock-service/stock/reduce", String.class);
return "下单成功!" + message;
}
}
边栏推荐
- [foobar 2000] how to play music stored on another computer in the LAN on mobile phones and computers? FTP server, upnp/dlna protocol, building music server, creating music server
- JVM performance tuning method
- Latex basic grammar summary
- 虚拟机Centos搭建MySQL集群——一主多从
- YoloV7:基于自己训练的模型如何导出正确的ONNX
- Software designer: 11 basic knowledge examples
- 【Unity3D】UGUI之布局组件
- UVA10341 Solve It
- Date and time function of MySQL function summary
- Basic use of anaconda and its use in pychart
猜你喜欢

What is graph neural network?

个人 IP 实验室周复盘 · 第 19 期

Clouds want clothes, flowers want looks, spring breeze blows the sill, Revlon (romantic code implementation)

System information function of MySQL function summary

Uniapp authorized login to obtain user information and code

VS2019 MFC Slider Control 控件继承CSliderCtrl类重绘 自绘

云服务ECS/RDS:搭建云服务器ECS管理linux,搭建云数据库管理创建RDS MySQL;

JMeter 21 天打卡 day10

OS知识点简介(二)

圆环形材质mask
随机推荐
啥是图神经网络?
Condition judgment function of MySQL function summary
epoll的ET工作模式和LT工作模式
在go中使用yaml
向数据库表中插入中文数据报错“1366 (HY000): Incorrect string value: ‘\xE5\x90\x95\xE5‘ for column ‘name‘ at row 1“
QA机器人第二节——召回
文件上传通用测试点归纳总结
奥扬科技IPO被终止注册:年营收8亿 苏伟持有67.5%股权
Dijkstra序列(DAY 66)
[foundation of deep learning] how to understand the channel in convolutional neural network
JMeter 21 天打卡 day10
1805. 字符串中不同整数的数目 ●
Nacos配置文件获取不到 动态刷新失效问题解决
MATLAB学习第四天(决策语句)
Realization of communication between ROS and stm32
Build MySQL Cluster with virtual machine CentOS -- one master and many slaves
CANoe:.vmodule文件是什么
Vs2019 list control control self drawing routine inherits CListCtrl class onnmcustomdraw redrawing
[C language] 10000 word document operation summary
JMeter 21 day clock in Day10