SpringCloudAlibaba 集成Dubbo、Nacos 以及Hoxton.SR12版本问题解决

目录

一、SpringCloudAlibaba集成Dubbo、Nacos

二、版本问题解决


一、SpringCloudAlibaba集成Dubbo、Nacos

集成常规操作这个博主已经写的很详细了:

Spring Cloud Alibaba学习(九):Dubbo集成_IcyDate的博客-CSDN博客_dubbo集成

不过个人推荐将扫描包的配置放到配置文件:

如:

服务提供者:

server:
  port: 8881
spring:
  cloud:
    nacos:
      server-addr: localhost:8848 # nacos的服务配置
      discovery:
        cluster-name: Service_cluster_1  #集群
        group: Service_group_1  # 分组名
        username: nacos # 用户名
        password: nacos # 密码
        namespace: public  # 环境分类
  application:
    name: dubbo-provider
dubbo:
  protocol:
    name: dubbo
    port: -1
  registry:
    address: spring-cloud://localhost:8848
  scan: #dubbo的服务路径
    base-packages: com.wxl.service

服务消费者:多添加一个订阅提供者名称会更规范

server:
  port: 8882
spring:
  cloud:
    nacos:
      server-addr: localhost:8848 # nacos的服务配置
      discovery:
        cluster-name: Service_cluster_1  #集群
        group: Service_group_1  # 分组名
        username: nacos # 用户名
        password: nacos # 密码
        namespace: public  # 环境分类
  application:
    name: dubbo-consumer
dubbo:
  protocol:
    name: dubbo
    port: -1
  registry:
    address: spring-cloud://localhost:8848
  cloud:
    subscribed-services: dubbo-provider  #订阅的提供者名称

注意:先启动服务提供者,再启动服务消费者

二、版本问题解决

我用的是比较新的版本:Hoxton.SR12系列

按照该博主的操作,理论是没有问题的,但事实是新版本还是有一定的坑的,启动即报错如下:

***************************
APPLICATION FAILED TO START
***************************

Description:

An attempt was made to call a method that does not exist. The attempt was made from the following location:

    org.apache.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor.<init>(ReferenceAnnotationBeanPostProcessor.java:106)

The following method did not exist:

    org.apache.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor.setClassValuesAsString(Z)V

The method's class, org.apache.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor, is available from the following locations:

    jar:file:/D:/apache-maven-3.8.1/maven-repository/org/apache/dubbo/dubbo/2.7.13/dubbo-2.7.13.jar!/org/apache/dubbo/config/spring/beans/factory/annotation/ReferenceAnnotationBeanPostProcessor.class

The class hierarchy was loaded from the following locations:

    org.apache.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor: file:/D:/apache-maven-3.8.1/maven-repository/org/apache/dubbo/dubbo/2.7.13/dubbo-2.7.13.jar
    com.alibaba.spring.beans.factory.annotation.AbstractAnnotationBeanPostProcessor: file:/D:/apache-maven-3.8.1/maven-repository/com/alibaba/spring/spring-context-support/1.0.10/spring-context-support-1.0.10.jar
    org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessorAdapter: file:/D:/apache-maven-3.8.1/maven-repository/org/springframework/spring-beans/5.2.15.RELEASE/spring-beans-5.2.15.RELEASE.jar


Action:

Correct the classpath of your application so that it contains a single, compatible version of org.apache.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor

这很明显是jar包冲突问题!!!但调了一天我也没解决该问题,人都麻了,后来终于找到了一篇官方回应该问题的文章顺利解决:

升级 2.2.7 报错 · Issue #2310 · alibaba/spring-cloud-alibaba · GitHub

这是官方的回应,解决方法很简单,就是添加一个配置:

         <dependency>
            <groupId>com.alibaba.spring</groupId>
            <artifactId>spring-context-support</artifactId>
            <version>1.0.11</version>
        </dependency>

原本系列的是1.0.10但这里要顺利集成dubbo需要升级为1.0.11。

解决后运行,发现rpc调用正常:

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值