企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
当前`springboot`版本为`2.3.4`,`dubbo`最新版本为`2.7.8` ***** ### 1.引入依赖(服务提供者和服务消费者都要引入) ``` <!-- 导入dubbo starter--> <dependency> <groupId>org.apache.dubbo</groupId> <artifactId>dubbo-spring-boot-starter</artifactId> <version>2.7.8</version> </dependency> <!--zookeeper 注册中心客户端引入 使用的是curator客户端 --> <dependency> <groupId>org.apache.dubbo</groupId> <artifactId>dubbo-dependencies-zookeeper</artifactId> <version>2.7.8</version> <type>pom</type> <exclusions> <exclusion> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> </exclusion> </exclusions> </dependency> ``` ***** ### 2.配置 #### 1)服务提供者配置: ``` dubbo.application.name=springboot-dubbo-provider #配置扫描包 dubbo.scan.base-packages=com/youge/gmall/service/impl #zookeeper注册中心地址 dubbo.registry.address=127.0.0.1:2181 dubbo.registry.protocol=zookeeper dubbo.registry.timeout=10000 # dubbo.protocol.name=dubbo dubbo.protocol.port=20880 ``` #### 2)服务消费者配置: ``` dubbo.application.name=springboot-dubbo-consumer dubbo.consumer.check=false admin.config-center="zookeeper://127.0.0.1:2181 dubbo.registry.address=zookeeper://127.0.0.1:2181 dubbo.metadata-report.address=zookeeper://127.0.0.1:2181 dubbo.monitor.protocol=registry ``` ***** ### 3.注解 #### 1) `@EnableDubbo` //开启基于dubbo注解的功能 #### 2) `@DubboService` //暴露服务 #### 3) `@DubboReference` //引用