解决springboot整合dubbo中No provider available from registry 127.0.0.1:2181 for service x.x.x on consumer

解决springboot整合dubbo中No provider available from registry 127.0.0.1:2181 for service x.x.x on consumer

背景

今天接收一个项目,实在原有代码基础上增加一些功能,项目采用的架构是springboot+dubbo+mybatisPlus+zookeeper,按照原有程序结构,我试着谢了一个功能,结果在接口测试的时候报了500错误。
错误内容为:

No provider available from registry 127.0.0.1:2181 for service io.platform.jinyu.service.client.api.BizLiveServiceClient:1.0.0 on consumer 172.16.1.161 use dubbo version 2.6.2, please check status of providers(disabled, not registered or in blacklist).

如下图:
在这里插入图片描述

问题分析

错误的意思很明显就是在服务消费端的功能中调用服务提供端的逻辑时没有发现服务提供者对象。主要就是服务提供方代码的问题了,原服务提供放服务实现代码如下:

package io.platform.jinyu.service.client.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import io.platform.base.common.BaseServiceClient;
import io.platform.base.common.utils.ExecuteResult;
import io.platform.jinyu.biz.entity.BizLive;
import io.platform.jinyu.biz.service.BizLiveService;
import io.platform.jinyu.dto.BizLiveDto;
import io.platform.jinyu.service.client.api.BizLiveServiceClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @description:
 * @author: zheng
 * @date: Created in 2021/2/22 16:27
 * @version: 0.0.1
 * @modified By:
 */
@Component
@Service()
public class BizLiveServiceClientImpl extends BaseServiceClient<BizLive, BizLiveDto> implements BizLiveServiceClient {
    private Logger logger = LoggerFactory.getLogger(getClass());

    @Resource
    private BizLiveService bizLiveService;

    @Override
    public BizLiveDto queryObject(Long id) {
        BizLive bizLive = this.bizLiveService.selectById(id);
        BizLiveDto bizLiveDto = new BizLiveDto();
        BeanUtils.copyProperties(bizLive, bizLiveDto);
        return bizLiveDto;
    }

    @Override
    public List<BizLiveDto> queryList(Map<String, Object> map) {
        List<BizLive> bizLiveList = this.bizLiveService.selectByMap(map);
        return convertList(bizLiveList, BizLiveDto.class);
    }

    @Override
    public int queryTotal(Map<String, Object> map) {
        EntityWrapper<BizLive> ew = new EntityWrapper<>();
        ew.allEq(map);
        return this.bizLiveService.selectCount(ew);
    }
}

仔细观察上面的代码发现其中的类注解@Service所在的包为org.springframework.stereotype.Service,而用于标注对外暴露dubbo接口的@Service注解所在包为com.alibaba.dubbo.config.annotation.Service。

问题解决

通过修正@Service注解的包就解决了这个问题。

@Service注解在spring和dubbo中都有,很容易用错,因此在使用的过程中一定要注意,避免发生以上错误。

com.alibaba.dubbo.config.annotation.Service:用于标注对外暴露的dubbo接口实现类。
org.springframework.stereotype.Service:用于标注根据业务块分离的Service的实现类,对应的是业务层(如一个dubbo方法可能调用多个业务块的service,这些service的实现类就用Spring的注解)。

修改后重新启动provider服务,再次接口测试一切正常,如下图:
在这里插入图片描述

评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值