【springboot】springboot集成dubbo
程序员文章站
2022-07-12 20:57:09
...
前言
转载:https://my.oschina.net/u/3178270/blog/2995712
资料
服务端
- maven依赖
服务端和消费端依赖相同
<!-- dubbo --> <dependency> <groupId>com.alibaba.boot</groupId> <artifactId>dubbo-spring-boot-starter</artifactId> <version>0.2.0</version> </dependency> <!-- 基础依赖 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <!-- junit --> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> </dependency>
- 服务端配置文件
# base server.port=8002 spring.application.name=sentinel-dubbo-user-provider # dubbo ## dubbo.application.name:注册到dubbo的服务名称 ## dubbo.registry.address:dubbo注册地址 ## dubbo.registry.protocol:dubbo注册协议 ## dubbo.scan.base-packages:实现扫包范围 ## dubbo.protocol.port:暴露到dubbo的端口 dubbo.application.name=sentinel-dubbo-user-provider dubbo.registry.address=127.0.0.1:7001 dubbo.registry.protocol=zookeeper dubbo.scan.base-packages=com.demo dubbo.protocol.port=28002
- @Service注解为dubbo注解
import com.alibaba.dubbo.config.annotation.Service;
- 启动类注解
@SpringBootApplication(scanBasePackages = "com.demo.*") @EnableDubbo
消费端
- maven依赖
服务端和消费端依赖相同
<!-- dubbo --> <dependency> <groupId>com.alibaba.boot</groupId> <artifactId>dubbo-spring-boot-starter</artifactId> <version>0.2.0</version> </dependency> <!-- 基础依赖 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <!-- junit --> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> </dependency>
- 配置文件
服务端和消费端配置不同
# base server.port=8003 spring.application.name=sentinel-client # dubbo ## dubbo.application.name:注册到dubbo的服务名称 ## dubbo.registry.address:dubbo注册地址 ## dubbo.registry.protocol:dubbo注册协议 ## dubbo.scan.base-packages:实现扫包范围 ## dubbo.protocol.port:暴露到dubbo的端口 dubbo.application.name=sentinel-client dubbo.registry.address=127.0.0.1:7001 dubbo.registry.protocol=zookeeper dubbo.consumer.timeout=5000
- 调用服务端
@Reference private UserServiceApi userServiceApi;
- 启动类注解
@SpringBootApplication @EnableDubbo
以上,就是全部配置。
下面是在dubbo控制台查看服务信息
上一篇: linux下安装JDK8
推荐阅读
-
基于SpringBoot构造器注入循环依赖及解决方式
-
SpringBoot基于Shiro处理ajax请求代码实例
-
SpringBoot上下文初始器加载过程详解
-
SpringBoot加载应用事件监听器代码实例
-
springboot 报错 org.springframework.beans.factory.NoSuchBeanDefinitionException:No qualifying bean of type 'com.example.service.HrService' avai
-
详解SpringBoot应用跨域访问解决方案
-
详解SpringBoot 处理异常的几种常见姿势
-
SpringBoot项目使用RedisTemplate遇到key值\xac\xed\x00\x05t\x00的坑
-
SpringBoot集成JWT实现权限认证
-
[springboot 开发单体web shop] 4. Swagger生成Javadoc