SpringBoot整合dubbo(yml格式配置)

yml文件java

若是隻做爲服務的消費者不用暴露端口號,掃描的包名根據本身service改mysql

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文件git

springboot我用的2.1.4建議和我用同樣的,不同的話引入dubbo依賴版本也須要更改github

<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>

 

啓動類web

@EnableDubbo註解是開啓掃描dubbo服務的spring

@SpringBootApplication
//@MapperScan("com.bw.ssm.dao")
@EnableDubbo
public class Application {
    public static void main(String[] args) {
        springapplication.run - 這個網站可出售。 - 最佳的springapplication 來源和相關信息。(Application.class, args);
    }
}

 

Service層sql

 
 

引用dubbo服務的註解apache

 
 

最後

補充一下,pom文件不須要的依賴能夠自行去掉,我懶得去了。以上,告辭!
————————————————json

本人免費整理了Java高級資料,涵蓋了Java、Redis、MongoDB、MySQL、Zookeeper、Spring Cloud、Dubbo高併發分佈式等教程,一共30G,須要本身領取。
傳送門:https://mp.weixin.qq.com/s/osB-BOl6W-ZLTSttTkqMPQ

相關文章
相關標籤/搜索