yml文件
如果只作为服务的消费者不用暴露端口号,扫描的包名根据自己service改
dubbo: application: name: springboot-dubbo-demo #应用名 registry: address: zookeeper://127.0.0.1:2181 #zookeeper地址 # port: 2181 #提供注册的端口 protocol: name: dubbo port: "20889" #dubbo服务暴露的端口 scan: com.bw.ssm.service.impl #扫描的包名
pom文件
springboot我用的2.1.4建议和我用一样的,不一样的话引入dubbo依赖版本也需要更改
<dependencies> <dependency> <groupId>com.bw</groupId> <artifactId>interface-api</artifactId> <version>1.0-SNAPSHOT</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> <exclusions> <exclusion> <groupId>org.junit.vintage</groupId> <artifactId>junit-vintage-engine</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.18.10</version> <scope>provided</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <!-- com.alibaba " fastjson --> <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>1.2.58</version> </dependency> <!-- com.google.code.gson " gson --> <dependency> <groupId>com.google.code.gson</groupId> <artifactId>gson</artifactId> <version>2.8.5</version> </dependency> <!-- springboot整合mybatis --> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>1.3.0</version> </dependency> <!-- 连接mysql,注册驱动 --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency> <!-- 分页插件 --> <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper</artifactId> <version>4.1.3</version> </dependency> <!-- org.apache.logging.log4j " log4j-slf4j-impl --> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-slf4j-impl</artifactId> <version>2.11.0</version> </dependency> <!-- springboot整合dubbo+zookeeper --> <!--dubbo依赖--> <dependency> <groupId>com.alibaba.boot</groupId> <artifactId>dubbo-spring-boot-starter</artifactId> <version>0.2.0</version> </dependency> <!--<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-zookeeper-discovery</artifactId> <version>1.1.3.RELEASE</version> </dependency>--> <!--zkclient依赖--> <dependency> <groupId>com.101tec</groupId> <artifactId>zkclient</artifactId> <version>0.10</version> </dependency> <dependency> <groupId>org.apache.zookeeper</groupId> <artifactId>zookeeper</artifactId> <version>3.4.11</version> <type>pom</type> </dependency> </dependencies>
启动类
@EnableDubbo注解是开启扫描dubbo服务的
@SpringBootApplication //@MapperScan("com.bw.ssm.dao") @EnableDubbo public class Application { public static void main(String[] args) { springapplication.run - 这个网站可出售。 - 最佳的springapplication 来源和相关信息。(Application.class, args); } }
Service层
引用dubbo服务的注解
最后
补充一下,pom文件不需要的依赖可以自行去掉,我懒得去了。以上,告辞!
————————————————
本人免费整理了Java高级资料,涵盖了Java、Redis、MongoDB、MySQL、Zookeeper、Spring Cloud、Dubbo高并发分布式等教程,一共30G,需要自己领取。
传送门:https://mp.weixin.qq.com/s/osB-BOl6W-ZLTSttTkqMPQ
原文地址:https://www.cnblogs.com/yunxi520/p/12077693.html
时间: 2024-11-02 12:20:35