栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Dubbo(三)Hello测试(SpringBoot)(阿里巴巴包下的)

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Dubbo(三)Hello测试(SpringBoot)(阿里巴巴包下的)

一、创建发布者项目

dubbo-boot-service-provider

参考上一篇

包引用 pom.xm



    4.0.0
    
        org.springframework.boot
        spring-boot-starter-parent
        2.6.2
         
    
    
    
    
    
    
    
    com.hhm
    dubbo-boot-service-provider
    0.0.1-SNAPSHOT
    dubbo-boot-service-provider
    dubbo的发布者
    jar
    
        1.8
        2.6.2
        2.7.8
        true
    
    
        
            
            
                org.springframework.boot
                spring-boot-dependencies
                ${spring-boot.version}
                pom
                import
            

            
            
                org.apache.dubbo
                dubbo-dependencies-bom
                ${dubbo.version}
                pom
                import
            

            
                org.apache.dubbo
                dubbo
                ${dubbo.version}
                
                    
                        org.springframework
                        spring
                    
                    
                        javax.servlet
                        servlet-api
                    
                    
                        log4j
                        log4j
                    
                
            
        
    
    
        
            org.springframework.boot
            spring-boot-starter-web
        
        
            org.springframework.boot
            spring-boot-starter-test
            test
        
        
            org.example
            dubbo-demo-service
            1.0-SNAPSHOT
        
        
        
            com.101tec
            zkclient
            0.10
        
        
        
            com.alibaba.spring.boot
            dubbo-spring-boot-starter
            2.0.0
        
    
        
            
                
                    org.springframework.boot
                    spring-boot-maven-plugin
                
            
        


配置文件 application.properties

dubbo.application.name=dubbo-boot-service-provider

dubbo.registry.protocol=zookeeper
dubbo.registry.address=127.0.0.1
dubbo.registry.port=2181

server.port=8081
# 开启指定dubbo服务
spring.dubbo.server=true

程序实现

    @Component
    @Service(interfaceClass = UserService.class,version = "1.0.0",register = true)
public class UserServiceImpl implements UserService {

引用的包是

import com.alibaba.dubbo.config.annotation.Service;

启动类

@SpringBootApplication
@EnableDubbo

导入的包是

import com.alibaba.dubbo.config.spring.context.annotation.EnableDubbo;

消费者项目可以不变

需要替换的话,实现类

@Reference(interfaceClass = UserService.class,version = "1.0.0",check = false)

 引用的包

 

import com.alibaba.dubbo.config.annotation.Reference;

启动类

@EnableDubboConfiguration

这种方式不需要启动监控中心

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/704324.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号