Springboot1.X整合Nacos,出现Error creating bean with name ‘nacosAutoServiceRegistration‘ defined in class

项目启动报错:

spring boot:1.5.3
nacos:1.5.1

2022-06-10 09:16:44 |ERROR |main |SpringApplication.java:815 |org.springframework.boot.SpringApplication |Application startup failed
org.springframework.beans.factory.BeanCreationException
: Error creating bean with name 'nacosAutoServiceRegistration' defined in class path resource 
[com/alibaba/cloud/nacos/NacosDiscoveryAutoConfiguration.class]
: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate 
[com.alibaba.cloud.nacos.registry.NacosAutoServiceRegistration]
: Factory method 'nacosAutoServiceRegistration' threw exception; 
nested exception is java.lang.NoSuchMethodError
: org.springframework.cloud.client.serviceregistry.AbstractAutoServiceRegistration.<init>
(Lorg/springframework/cloud/client/serviceregistry/ServiceRegistry;
Lorg/springframework/cloud/client/serviceregistry/AutoServiceRegistrationProperties;)V

网上查找资料发现是Nacos与SpringBoot1.X有兼容问题

需要升级spring-cloud-commons版本到1.3.5.RELEASE

        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
            <version>1.5.1.RELEASE</version>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.cloud</groupId>
                    <artifactId>spring-cloud-commons</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
            <version>1.5.1.RELEASE</version>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.cloud</groupId>
                    <artifactId>spring-cloud-commons</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <!--解决nocas与Springboot1.x兼容问题 。升级 spring-cloud-commons 版本 -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-commons</artifactId>
            <version>1.3.5.RELEASE</version>
        </dependency>

总结:SpringBoot与Nacos整合时需要关注双方版本的兼容性

文章引用:https://blog.csdn.net/Juwenzhe_HEBUT/article/details/106344358

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值