当前位置:网站首页 > 去中心化金融(DeFi) > 正文

Nacos配置中心使用(nacos配置中心不生效)



Spring Cloud 2021.0

.5.0 是

Spring Cloud

一个

版本

,它可以和 Sentinel-datasource-

nacos

模块一起

使用

。下面是

使用 Spring Cloud 2021.0

.5.0 和 Sentinel-datasource-

nacos

的步骤:

1. 在 pom.xml 文件中引入以下依赖:

 <dependency> <groupId>org. spring framework. cloud </groupId> <artifactId> spring - cloud -starter-alibaba-sentinel</artifactId> <version> 2021.0 .5.0</version> </dependency> <dependency> <groupId>com.alibaba. cloud </groupId> <artifactId> spring - cloud -alibaba- nacos -discovery</artifactId> <version>2.2.5.RELEASE</version> </dependency> <dependency> <groupId>com.alibaba. cloud </groupId> <artifactId> spring - cloud -alibaba- nacos -config</artifactId> <version>2.2.5.RELEASE</version> </dependency> 

2. 配置

Nacos

作为 Sentinel 的数据源,例如:

  spring :  cloud : sentinel: transport: dashboard: localhost:8080 port: 8719  nacos : server-addr: localhost:8848 groupId: DEFAULT_GROUP dataId: sentinel rule-type: flow 

3. 在

Nacos

创建对应的命名空间和配置文件,例如:

  spring :  cloud : sentinel: transport: dashboard: localhost:8080 port: 8719  nacos : server-addr: localhost:8848 groupId: DEFAULT_GROUP dataId: sentinel rule-type: flow data-type: json namespace: 7e1d4f1f-8a31-4f0d-9f8d-0d4a563beba4 

4. 在应用程序中添加 Sentinel 规则,例如:

 java @PostConstruct public void init() throws Exception { String appName = env.getProperty(" spring .application.name"); ReadableDataSource<String, List<FlowRule>> flowRuleDataSource = new Nacos DataSource<>( nacos ServerAddr, groupId, appName + "-flow-rule", source -> JSON.parseObject(source, new TypeReference<List<FlowRule>>() {})); FlowRuleManager.register2Property(flowRuleDataSource.getProperty()); } 

以上是

Spring Cloud 2021.0

.5.0

使用

Sentinel-datasource-

nacos

的基本步骤,具体实现可以根据项目需要进行调整。

到此这篇Nacos配置中心使用(nacos配置中心不生效)的文章就介绍到这了,更多相关内容请继续浏览下面的相关推荐文章,希望大家都能在编程的领域有一番成就!

版权声明


相关文章:

  • 静脉药物配置中心出科小结(静脉药物配置中心工作)2025-07-24 09:27:08
  • Apollo配置中心页面长什么样(apollo 配置中心 github)2025-07-24 09:27:08
  • 静脉药物配置中心在中药领域的重要性(静脉药物配置中心的作用)2025-07-24 09:27:08
  • 本机短信中心的号码是什么(本机短信验证码是什么号码)2025-07-24 09:27:08
  • 怎么把文件管理里的音频转出去(怎么把文件管理的音频转化成mp3)2025-07-24 09:27:08
  • Apollo配置中心满足cp还是ap(apollo配置中心动态更新)2025-07-24 09:27:08
  • Nacos配置中心只有key没有value(nacos配置中心有啥作用)2025-07-24 09:27:08
  • 配置中心的作用(配置中心的主要作用)2025-07-24 09:27:08
  • Apollo配置中心是基于文件吗(apollo配置中心的缺点)2025-07-24 09:27:08
  • 静脉药物配置中心的发展(简述静脉药物配置中心的工作流程)2025-07-24 09:27:08
  • 全屏图片