学无先后,达者为师

网站首页 编程语言 正文

eureka更换为nacos

作者:YXWik6 更新时间: 2022-07-12 编程语言

1.先安装好nacos
2.在项目中引入nacos配置文件
这里的0.2.1版本出现了一些问题,所以更改为了0.2.2版本

        <!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-alibaba-			nacos-discovery -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-alibaba-nacos-discovery</artifactId>
            <version>0.2.2.RELEASE</version>
        </dependency>

配置文件中配置nacos

spring.application.name=nacos-config
spring.cloud.nacos.username=nacos
spring.cloud.nacos.password=nacos123456
spring.cloud.nacos.discovery.server-addr=192.168.0.180:8848

在这里插入图片描述

3.删除eureka相关jar包
在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

发现删不干净,于是在配置文件中进行设置排除eureka

eureka.client.register-with-eureka=false
eureka.client.fetchRegistry=false
eureka.client.server.waitTimeInMsWhenSyncEmpty=0
spring.autoconfigure.exclude: org.springframework.cloud.netflix.eureka.EurekaClientAutoConfiguration

在这里插入图片描述

4.相关问题
1)如果出现报错:create config service error!properties=NacosConfigProperties{serverAddr=‘null‘, encode=‘null‘
则需要把 Nacos Config配置的依赖去掉就可以了
在这里插入图片描述
2)
java.lang.IllegalStateException: failed to req API:/nacos/v1/ns/instance after all servers([192.168.0.180:8848]) tried在这里插入图片描述

网上寻找解决方案
解决方案1:原因是nacos服务器过载,到nacos文件夹下去删掉data文件夹再重启Nacos就可以了
但是这里我尝试了并没有解决问题

解决方案2:
在这里插入图片描述
因为我这里的版本就是0.2.1,所以这也不能解决我的问题

解决方案3:
打开nacos的配置文件
在这里插入图片描述

在这里插入图片描述
并没有解决问题
找了一圈无果,决定从版本开始入手
将spring-cloud-alibaba-nacos-discovery 版本的0.2.1更改为0.2.2结果问题解决了
在这里插入图片描述

原文链接:https://blog.csdn.net/YXWik/article/details/125715305

栏目分类
最近更新