前言
转载:https://my.oschina.net/u/3178270/blog/2995712
资料
- @EnableDubbo含义
https://blog.csdn.net/qq_29064815/article/details/103067208
服务端
- 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控制台查看服务信息