欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

SpringBoot整合dubbo(yml格式配置)

程序员文章站 2022-06-14 20:05:24
yml文件 如果只作为服务的消费者不用暴露端口号,扫描的包名根据自己service改 dubbo: application: name: springboot-dubbo-demo #应用名 registry: address: zookeeper://127.0.0.1:2181 #zookeep ......

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层

 
SpringBoot整合dubbo(yml格式配置)
 

引用dubbo服务的注解

 
SpringBoot整合dubbo(yml格式配置)
 

最后

补充一下,pom文件不需要的依赖可以自行去掉,我懒得去了。以上,告辞!
————————————————

本人免费整理了java高级资料,涵盖了java、redis、mongodb、mysql、zookeeper、spring cloud、dubbo高并发分布式等教程,一共30g,需要自己领取。
传送门:https://mp.weixin.qq.com/s/osb-bol6w-zltstttkqmpq