久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁技術文章
文章詳情頁

Spring Cloud Alibaba Nacos Config配置中心實現

瀏覽:3日期:2023-09-11 11:26:28

什么是 Nacos Config

在分布式系統中,由于服務數量巨多,為了方便服務 配置文件統一管理,實時更新,所以需要分布式配置中心組件。

Spring Cloud Alibaba Nacos Config 是 Spring Cloud Config 的替代方案。

Nacos Config 的存儲配置功能為分布式系統中的外部化配置提供服務器端和客戶端支持,可以在 Nacos 中集中管理 Spring Cloud 應用的外部屬性配置。

引入依賴

在 pom.xml 中添加 spring-cloud-starter-alibaba-nacos-config 依賴

<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId></dependency>

在 Nacos 控制臺中發布配置

訪問 Nacos 控制臺,在配置列表中新建一個配置

Spring Cloud Alibaba Nacos Config配置中心實現

在該頁面中添加項目配置信息

注:Nacos Config 中的配置內容不能帶有注釋,否則項目啟動會失敗

Spring Cloud Alibaba Nacos Config配置中心實現

相關配置

需要在 bootstrap.properties 中優先配置 Nacos Config 客戶端

spring.profiles.active=devspring.application.name=service-provider-configspring.cloud.nacos.config.server-addr=192.168.127.132:8848spring.cloud.nacos.config.file-extension=yaml

注:Spring Boot 配置文件的加載順序,依次為 bootstrap.properties > bootstrap.yaml > application.properties > application.yaml

在 Application 入口類中添加注解 @RefreshScope 開啟動態刷新配置功能

import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.cloud.context.config.annotation.RefreshScope;@SpringBootApplication@RefreshScopepublic class ConsumerApplication { public static void main(String[] args) { SpringApplication.run(ConsumerApplication.class, args); }}

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。

標簽: Spring
相關文章:
主站蜘蛛池模板: 大姚县| 北票市| 荆门市| 仙居县| 文成县| 庄浪县| 德州市| 嘉兴市| 巨鹿县| 临西县| 乐山市| 延边| 衡阳市| 广东省| 宣汉县| 郎溪县| 澄迈县| 洪洞县| 奉化市| 宁陵县| 青铜峡市| 施甸县| 通海县| 崇义县| 珲春市| 积石山| 绥宁县| 湖州市| 兰西县| 伊金霍洛旗| 阜南县| 六安市| 库伦旗| 遵义县| 绥德县| 清苑县| 定州市| 平利县| 漳平市| 丹巴县| 罗平县|