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

Dubbo(三)Hello测试(SpringBoot)(阿里巴巴包下的),第1张

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

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

欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/zaji/5706412.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存