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

Nacos配置中心使用(nacos配置中心不生效)Spring Cloud 2021 0 5 0 是 Spring Cloud 的一个版本 它可以和 Sentinel datasource nacos 模块一起使用 下面是使用 Spring Cloud 2021 0 5 0 和 Sentinel datasource nacos 的步骤 在 pom xml 文件中引入以下依赖 lt

大家好,我是讯享网,很高兴认识大家。

Spring Cloud 2021.0.5.0 是 Spring Cloud 的一个版本,它可以和 Sentinel-datasource-nacos 模块一起使用。下面是使用 Spring Cloud 2021.0.5.0 和 Sentinel-datasource-nacos 的步骤:


讯享网

  1. 在 pom.xml 文件中引入以下依赖:
&lt;dependency&gt; &lt;groupId&gt;org.<em>spring</em>framework.<em>cloud</em>&lt;/groupId&gt; &lt;artifactId&gt;<em>spring</em>-<em>cloud</em>-starter-alibaba-sentinel&lt;/artifactId&gt; &lt;version&gt;<em>2021.0</em>.5.0&lt;/version&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;com.alibaba.<em>cloud</em>&lt;/groupId&gt; &lt;artifactId&gt;<em>spring</em>-<em>cloud</em>-alibaba-<em>nacos</em>-discovery&lt;/artifactId&gt; &lt;version&gt;2.2.5.RELEASE&lt;/version&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;com.alibaba.<em>cloud</em>&lt;/groupId&gt; &lt;artifactId&gt;<em>spring</em>-<em>cloud</em>-alibaba-<em>nacos</em>-config&lt;/artifactId&gt; &lt;version&gt;2.2.5.RELEASE&lt;/version&gt; &lt;/dependency&gt; 

讯享网
  1. 配置 Nacos 作为 Sentinel 的数据源,例如:
讯享网<em>spring</em>: <em>cloud</em>: sentinel: transport: dashboard: localhost:8080 port: 8719 <em>nacos</em>: server-addr: localhost:8848 groupId: DEFAULT_GROUP dataId: sentinel rule-type: flow 
  1. Nacos 中创建对应的命名空间和配置文件,例如:
<em>spring</em>: <em>cloud</em>: sentinel: transport: dashboard: localhost:8080 port: 8719 <em>nacos</em>: server-addr: localhost:8848 groupId: DEFAULT_GROUP dataId: sentinel rule-type: flow data-type: json namespace: 7e1d4f1f-8a31-4f0d-9f8d-0d4a563beba4 
  1. 在应用程序中添加 Sentinel 规则,例如:
讯享网@PostConstruct public void init() throws Exception { String appName = env.getProperty(&quot;<em>spring</em>.application.name&quot;); ReadableDataSource&lt;String, List&lt;FlowRule&gt;&gt; flowRuleDataSource = new <em>Nacos</em>DataSource&lt;&gt;(<em>nacos</em>ServerAddr, groupId, appName + &quot;-flow-rule&quot;, source -&gt; JSON.parseObject(source, new TypeReference&lt;List&lt;FlowRule&gt;&gt;() {})); FlowRuleManager.register2Property(flowRuleDataSource.getProperty()); } 

以上是 Spring Cloud 2021.0.5.0 使用 Sentinel-datasource-nacos 的基本步骤,具体实现可以根据项目需要进行调整。

小讯
上一篇 2025-06-07 18:55
下一篇 2025-06-05 23:21

相关推荐

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/162457.html