Spring Cloud Alibaba 初体验(三) Nacos 与 Dubbo 集成
一、新建项目
新建项目,只放置接口,用于暴露 Dubbo 服务接口
public interface GreetingService {
String greeting();
}
二、provider
本文以上文中的 Service1 作为 provider,以 Service2 作为 consumer
2.1 添加依赖
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-dubbo</artifactId>
</dependency>
2.2 实现接口
@Service
@Component
public class GreetingServiceImpl implements GreetingService {
@Value("${server.port:0}")
private Integer port;
@Override
public String greeting() {
return "hello from port: " + port;
}
}
@Service 为 org.apache.dubbo.config.annotation.Service (旧的版本为 com.alibaba.dubbo.config.annotation.Service),此处的 @Service 只能供 Dubbo RPC 调用,如果需要像之前一样正常在 Controller 层调用需要再添加 @Component 注解 (或者直接不添加 @Component 在项目内也通过 Dubbo 调用)
2.3 新增配置
dubbo:
scan:
base-packages: com.karonda.service1.service.impl
protocol:
name: dubbo
port: -1 # -1 表示端口自增
registry:
address: nacos://192.168.92.1:8848
三、consumer
3.1 调用服务
@Reference
private GreetingService greetingService;
@RequestMapping("/dubboGreeting")
public String dubboGreeting() {
return greetingService.greeting();
}
@Reference 为 org.apache.dubbo.config.annotation.Reference (旧的版本为 com.alibaba.dubbo.config.annotation.Reference)
3.2 新增配置
dubbo:
protocol:
name: dubbo
port: -1
registry:
address: nacos://192.168.92.1:8848
consumer:
check: false # 不加此配置项目启动时可能会失败
启动服务,访问 http://localhost:8079/dubboGreeting 可以看到结果
Spring Cloud Alibaba 初体验(三) Nacos 与 Dubbo 集成的更多相关文章
- Spring Cloud Alibaba 初体验(一) Nacos 配置中心
一.Nacos 下载与初始化配置 本文使用1.2.0,下载地址:https://github.com/alibaba/nacos/releases Nacos 单机模式支持持久化配置到 MySQL 数 ...
- Spring Cloud Alibaba 初体验(二) Nacos 服务注册与发现 + 集成 Spring Cloud Gateway
一.服务注册 添加依赖: <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>s ...
- Spring Cloud Alibaba 初体验(六) Seata 及结合 MyBatis 与 MyBatis-Plus 的使用
一.下载与运行 本文使用 Seata 1.1.0:https://github.com/seata/seata/releases Windows 环境下双击 bin/seata-server.bat ...
- Spring Cloud Alibaba 初体验(四) Sentinel
一.Sentinel 下载与运行 本文使用 Sentinel 1.7.1:https://github.com/alibaba/Sentinel/releases 使用自定义端口 8089 运行 Se ...
- Spring Cloud Alibaba 初体验(五) SkyWalking
一.下载与运行 本文使用 SkyWalking 7.0.0:https://www.apache.org/dyn/closer.cgi/skywalking/7.0.0/apache-skywalki ...
- Spring Cloud Alibaba基础教程:Nacos配置的多环境管理
前情回顾: <Spring Cloud Alibaba基础教程:使用Nacos实现服务注册与发现> <Spring Cloud Alibaba基础教程:支持的几种服务消费方式> ...
- Spring Cloud Alibaba基础教程:Nacos的集群部署
继续说说生产环境的Nacos搭建,通过上一篇<Spring Cloud Alibaba基础教程:Nacos的数据持久化>的介绍,我们已经知道Nacos对配置信息的存储原理,在集群搭建的时候 ...
- Spring Cloud Alibaba基础教程:Nacos的数据持久化
前情回顾: <Spring Cloud Alibaba基础教程:使用Nacos实现服务注册与发现> <Spring Cloud Alibaba基础教程:支持的几种服务消费方式> ...
- Spring Cloud Alibaba基础教程:Nacos配置的多文件加载与共享配置
前情回顾: <Spring Cloud Alibaba基础教程:使用Nacos实现服务注册与发现> <Spring Cloud Alibaba基础教程:支持的几种服务消费方式> ...
随机推荐
- 【SpringBoot】04.SpringBoot整合Filter的两种方式
SpringBoot整合Filter过滤器的两种方式: 1.通过扫描注解完成Filter组件注册 创建一个类,实现Filter接口,实现doFilter()方法 在该类使用注解@WebFilter,设 ...
- 利用sklearn实现knn
基于上面一篇博客k-近邻利用sklearns实现knn #!/usr/bin/env python # coding: utf-8 # In[1]: import numpy as np import ...
- 案例:简易的Div拖拽
案例:简易的Div拖拽 鼠标移入Div区域后,按下鼠标左键,可以拖动Div移动;松开鼠标左键,Div拖动停止.同时要求Div不能拖出屏幕显示区域外. 拖拽原理:距离不变.三个事件(onmousedow ...
- martini-拓扑映射
如何为一个新的分子创建拓扑文件? 这是martini应用的关键.http://jerkwin.github.io/2016/08/31/Martini%E5%B8%B8%E8%A7%81%E9%97% ...
- Selective Acknowledgment 选项 浅析 1
抓包的时候,发现 tcp 三次握手中一般会有几个options 一个是mss 一个是ws 一个sack perm 这次主要是来说一说 sack 这个选项: 1. 只重传超时的数据包,比较实用与后 ...
- 1、线性DP 213. 打家劫舍 II
https://leetcode-cn.com/problems/house-robber-ii/ //rob 0, not rob n-1 || not rob 0,not rob n-1 ==&g ...
- CSP-S 2020 Travels
CSP-S 2020 Travels DAY 0 I hit the board in the morning before departure The rest of the time is dec ...
- maven pom.xml 报错
首先介绍背景,在eclipse中导入一个maven的项目,在我之前的电脑上导入好用,在自己的电脑上导入居然pom报错了Missing artifact junit:junit:jar:4.11,还会有 ...
- opencv 学习1 gui属性
1.图像 先定一个小目标学习两个个功能 1.学习怎样读入一副画像,以及如何保存一副图像 2.学习三个函数cv2.imread(), cv2.imshow() , cv2.imwrite() 1.1读入 ...
- MFC详解
MFC的消息响应机制详解: 1.MFC是Windows下程序设计的最流行的一个类库,但是该类库比较庞杂,尤其是它的消息映射机制,更是涉及到很多低层的东西,接下来详细讲解. 2.在讲解MFC的消息响应之 ...