Spring Boot集成Dubbo应用(1):Dubbo+Zk简单的入门案例

本文介绍了如何将Spring Boot与Dubbo结合,创建一个包含接口工程、服务提供者和消费者的应用。首先,展示了接口工程定义的基本接口,接着详细讲述了服务提供者工程的配置,包括pom.xml和yml文件,以及业务实现类和启动类的编写。随后,解释了服务消费者工程的构建,包括引入web依赖,配置文件和控制器代码。最后,指导了如何运行项目并访问接口。
摘要由CSDN通过智能技术生成

开始

下面是该demo所涉及到所有的工程,再此之前,记得打开Zookeeper
工程

接口工程/api

该工厂只提供一个接口,但并没有实现

就这样,over,然后 执行命令 mvn clean install 打包到本地库,好给别的工程调用,真实开发中,都是通过mvn deploy 命令,传到私库(nexus)中,供团队统一调用的

配置父类/parent

pom文件配置

 <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.7.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.sunfounder</groupId>
    <artifactId>dubbo-service-user-parent</artifactId>
    <version>1.0.0</version>
    <name>dubbo-service-user-parent</name>
    <properties>
        <java.version>1.8</java.version>
        <dubbo.version>2.7.1</dubbo.version>
        <spring-boot.version>2.1.7.RELEASE</spring-boot.version>
    </properties>
    <dependencyManagement>
    <dependencies>
            <!-- Spring Boot -->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>${spring-boot.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>

            <!-- Apache Dubbo  -->
            <dependency>
                <groupId>org.apache.dubbo</groupId>
                <artifactId>dubbo-dependencies-bom</artifactId>
                <version>${dubbo.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>

            <dependency>
                <groupId>org.apache.dubbo</groupId>
                <artifactId>dubbo</artifactId>
                <version>${dubbo.version}</version>
                <exclusions>
                    <exclusion>
                        <groupId>org.springframework</groupId>
                        <artifactId>spring</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>javax.servlet</groupId>
                        <artifactId>servlet-api</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>log4j</groupId>
                        <artifactId>log4j</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>

        <!-- interface jar -->
        <dependency>
            <groupId>com.sunfounder</groupId>
            <artifactId>dubbo-service-user-api</artifactId>
            <version>1.0.0</version>
        </dependency>
        <!-- 状态检查 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>

        <!-- Dubbo Spring Boot Starter -->
        <dependency>
            <groupId>com.alibaba.boot</groupId>
            <artifactId>dubbo-spring-boot-starter</artifactId>
            <version>0.2.0</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

就这样,over,什么都不要动,后面要用这个工程做父类的,

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值