一、前言
Nacos Config Starter
實現(xiàn)了 org.springframework.cloud.bootstrap.config.PropertySourceLocator
接口,并將優(yōu)先級設置為最高。
在 Spring Cloud
應用啟動階段,會主動從 Nacos Server
端獲取對應的數(shù)據,并將獲取到的數(shù)據轉換成 PropertySource
且注入到 Environment
的 PropertySources
屬性中,所以使用 @Value
注解也能直接獲取 Nacos Server
端配置的內容。
二、本地配置覆蓋遠程配置
前言部分已說明
Nacos Config Starter
將遠程配置優(yōu)先級設置成為最高,故需要在遠程配置中心(nacos)上設置本地配置覆蓋遠程配置。文章來源:http://www.zghlxwxcb.cn/news/detail-614985.html
在遠程的${prefix}-${spring.profiles.active}.${file-extension}
中配置以下部分:文章來源地址http://www.zghlxwxcb.cn/news/detail-614985.html
spring:
cloud:
到了這里,關于Spring Cloud集成Nacos實現(xiàn)本地配置優(yōu)先 | Spring Cloud 9的文章就介紹完了。如果您還想了解更多內容,請在右上角搜索TOY模板網以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網!