springcloud eureka切换nacos的配置方法
作者:lsh2366254 时间:2022-05-19 01:58:47
springcloud eureka切换nacos
配置中心地址: http://10.166.9.7:8848/nacos/
bootstrap.yml文件修改
springcloudconfig配置
spring:
profiles: dev
cloud:
config:
uri: http://10.166.9.7:3301/
inetutils:
preferred-networks:
- 192.168
替换为nacos配置【以gateway-server为例子】
spring:
application:
name: gateway-server
main:
allow-bean-definition-overriding: true
cloud:
# spring cloud config配置
# config:
# uri: http://10.166.9.7:3301/
# 默认网卡获取配置示例 spring.cloud.inetutils.preferred-networks=192.168.*
# inetutils:
# preferredNetworks:
# - 192.168.*
#nacos的配置文件(DataID)默认的加载规则是: ${prefix}- ${spring.profiles.active}- ${file-extension}
#本次配置未使用spring.profiles.active
nacos:
discovery:
#ip: 192.168
server-addr: nacos-${spring.profiles}.rxcx.com:8848
namespace: ${spring.profiles}
group: rxcx
#配置中心登录名称
username: nacos
#配置中心密码
password: Zwrx0803!
config:
server-addr: nacos-${spring.profiles}.rxcx.com:8848 #nacos配置中心地址
file-extension: yml #文件后缀
prefix: gateway-server #文件前缀
namespace: ${spring.profiles} #配置文件命名空间
#配置分组
group: rxcx
#配置中心登录名称
username: nacos
#配置中心密码
password: Zwrx0803!
#支持动态生效
refresh-enabled: true
#扩展配置文件
extension-configs[0]:
#配置文件名称
data-id: common.yml
#配置文件分组
group: rxcx
#支持动态生效
refresh: true
management.endpoints.web.exposure.include: '*'
---
spring:
profiles: dev
---
spring:
profiles: testwlhy
# cloud:
# config:
# uri: http://wlhy.config.com:3301/
---
spring:
profiles: test3A
# cloud:
# config:
# uri: http://172.30.0.181:3301/
# inetutils:
# preferred-networks: 192.168.210.*
---
spring:
profiles: product
# cloud:
# config:
# uri: http://172.16.1.29:3301/
pom.xml依赖修改
删除依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
<version>1.4.3.RELEASE</version>
</dependency>
新增依赖
#注意与springboot的版本对应
<!-- nacos 依赖 -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
<version>2.2.1.RELEASE</version>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
<version>2.2.1.RELEASE</version>
<exclusions>
<exclusion>
<groupId>com.netflix.ribbon</groupId>
<artifactId>ribbon</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-loadbalancer</artifactId>
</dependency>
启动文件修改【删除eureka配置】
删除@EnableEurekaClient即可
@SpringBootApplication(scanBasePackages = "com.chinaunicom.rxcx.gateway",exclude={ DataSourceAutoConfiguration.class , MongoAutoConfiguration.class, MongoDataAutoConfiguration.class})
@EnableDiscoveryClient
@EnableEurekaClient
@EnableFeignClients(basePackages="com.chinaunicom.rxcx")
@ComponentScan(basePackages="com.chinaunicom.rxcx")
public class GatewayServerApplication {
public static void main(String[] args) {
SpringApplication.run(GatewayServerApplication.class, args);
System.out.println("网关启动成功-v9");
}
}
替换为
@SpringBootApplication(scanBasePackages = "com.chinaunicom.rxcx.gateway",exclude={ DataSourceAutoConfiguration.class , MongoAutoConfiguration.class, MongoDataAutoConfiguration.class})
@EnableDiscoveryClient
@EnableFeignClients(basePackages="com.chinaunicom.rxcx")
@ComponentScan(basePackages="com.chinaunicom.rxcx")
public class GatewayServerApplication {
public static void main(String[] args) {
SpringApplication.run(GatewayServerApplication.class, args);
System.out.println("网关启动成功-v9");
}
}
学习文档参考
https://nacos.io/zh-cn/docs/v2/quickstart/quick-start.html
开发环境,目前已改造gateway,其余服务通过同步工具同步至nacos,保障服务正常
http://10.166.9.7:8083/#/serviceSync
错误
No Feign Client for loadBalancing defined.
spring-cloud-starter-alibaba-nacos-discovery依赖排除
com.netflix.ribbon ribbon
来源:https://blog.csdn.net/lsh2366254/article/details/128639855
标签:springcloud,eureka,切换,nacos
0
投稿
猜你喜欢
android自定义view制作圆形进度条效果
2021-09-14 08:05:54
SpringMvc微信支付回调示例代码
2023-01-24 08:00:03
SpringBoot如何读取xml配置bean(@ImportResource)
2021-08-03 22:33:44
Java定时任务的三种实现方法
2022-01-13 06:59:01
Spring框架初始化解析
2021-06-09 16:46:59
netty pipeline中的inbound和outbound事件传播分析
2023-08-27 06:57:00
Android沉浸式状态栏的实现代码
2023-08-21 05:52:08
Java NIO:浅析IO模型_动力节点Java学院整理
2022-01-17 17:07:38
Android事件分发机制全面解析
2023-05-11 06:53:49
解析Spring Mvc Long类型精度丢失问题
2021-11-06 12:27:37
JavaSE-面向对象(方法重写)
2023-01-27 10:51:09
Java经典面试题最全汇总208道(五)
2023-11-10 07:06:46
C#查找字符串所有排列组合的方法
2022-07-04 10:01:54
java编程之AC自动机工作原理与实现代码
2023-04-04 19:11:23
Java8 Stream流多字段求和、汇聚的实例
2023-03-14 20:17:23
Android 沉浸式状态栏及悬浮效果
2023-07-29 23:03:15
java 中堆内存和栈内存理解
2023-04-23 19:24:05
基于SpringBoot生成二维码的几种实现方式
2022-02-27 16:24:31
使用Spring组合自定义的注释 mscharhag操作
2023-02-14 11:18:01
Java递归运行的机制:递归的微观解读图文分析
2022-09-24 20:04:09