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

您的位置:首頁技術(shù)文章
文章詳情頁

Spring Cloud Alibaba Nacos Config配置中心實(shí)現(xiàn)

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

什么是 Nacos Config

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

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

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

引入依賴

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

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

在 Nacos 控制臺(tái)中發(fā)布配置

訪問 Nacos 控制臺(tái),在配置列表中新建一個(gè)配置

Spring Cloud Alibaba Nacos Config配置中心實(shí)現(xiàn)

在該頁面中添加項(xiàng)目配置信息

注:Nacos Config 中的配置內(nèi)容不能帶有注釋,否則項(xiàng)目啟動(dòng)會(huì)失敗

Spring Cloud Alibaba Nacos Config配置中心實(shí)現(xiàn)

相關(guān)配置

需要在 bootstrap.properties 中優(yōu)先配置 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 開啟動(dòng)態(tài)刷新配置功能

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); }}

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。

標(biāo)簽: Spring
相關(guān)文章:
主站蜘蛛池模板: 波密县| 迭部县| 临颍县| 虞城县| 峨边| 丽江市| 大埔县| 克拉玛依市| 武汉市| 周口市| 左权县| 华亭县| 南靖县| 乡宁县| 郑州市| 青州市| 安多县| 肥乡县| 马龙县| 榆树市| 武隆县| 新巴尔虎右旗| 永兴县| 比如县| 昌宁县| 揭西县| 万山特区| 津南区| 内丘县| 凯里市| 凤冈县| 肇庆市| 民权县| 繁峙县| 台北县| 富顺县| 汉沽区| 九江市| 沁源县| 安化县| 宁城县|