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基础教程:支持的几种服务消费方式> ...
随机推荐
- week01-绪论作业
一.有理数的抽象数据模型 ADT Rational { 数据对象: D={e1,e2|e1,e2属于ElemType类型}//ElemType为自定义的整数集合类型 数据关系: R={<e1,e ...
- [阿里DIN] 从模型源码梳理TensorFlow的乘法相关概念
[阿里DIN] 从模型源码梳理TensorFlow的乘法相关概念 目录 [阿里DIN] 从模型源码梳理TensorFlow的乘法相关概念 0x00 摘要 0x01 矩阵乘积 1.1 matmul pr ...
- 使用switch计算出某年某月某日是今年的第几天,输出一直是当月天数
package com.cx.Switch; import java.util.Scanner; /** * 计算出某年某月某日是今年的第几天 * 使用switch */ public class S ...
- binary hacks读数笔记(nm命令)
nm命令(names):输出包含三个部分:1 符号值.默认显示十六进制,也可以指定: 2 符号类型.小写表示是本地符号,大写表示全局符号(external); 3 符号名称. 例如:nm Simple ...
- 《GNU_Makefile》第4章——makefile规则
规则明确在什么情况下,使用什么方法,重构文件,该文件称为目标. make的唯一目的是重构终极目标.终极目标默认是第一个目标. 1. 2.规则语法 TARGETS : PREREQUISITES COM ...
- uboot——do_bootm
do_bootm |----------根据参数得到 image的起始地址 |----------比较header的 magic_num 是否为 zImage | |是 | | zImage路线 | ...
- 四:servlet最终形态
之前那么麻烦的创建servlet,其实创建是非常简单的 1.在src项目下右键new一个servlet即可 2. 这样生成的servlet会自动在web.xml生成一个映射的资源名字就和java类的名 ...
- 基于gin的golang web开发:中间件
gin中间件(middleware)提供了类似于面向切面编程或路由拦截器的功能,可以在请求前和请求之后添加一些自定义逻辑.实际开发中有很多场景会用到中间件,例如:权限验证,缓存,错误处理,日志,事务等 ...
- Python_爬虫笔记_2018.3.19
Python_爬虫_笔记 1.前言 1.1爬虫用途: 网站采集.接口采集(地图(jis 热力学 屋里端口/协议).微信.知乎.) 1.2基本流程:网页下载(requests)+网页解析+爬虫调度 网页 ...
- [LeetCode题解]142. 环形链表 II | 快慢指针
解题思路 本题是在141. 环形链表基础上的拓展,如果存在环,要找出环的入口. 如何判断是否存在环,我们知道通过快慢指针,如果相遇就表示有环.那么如何找到入口呢? 如下图所示的链表: 当 fast 与 ...