最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

SpringBoot Nacos實(shí)現(xiàn)自動(dòng)刷新

 更新時(shí)間:2023年01月14日 09:48:17   作者:我有一只肥螳螂  
這篇文章主要介紹了SpringBoot Nacos實(shí)現(xiàn)自動(dòng)刷新,Nacos(Dynamic Naming and Configuration Service)是阿里巴巴開(kāi)源的一個(gè)動(dòng)態(tài)服務(wù)發(fā)現(xiàn)、配置管理和服務(wù)管理平臺(tái)

背景

SpringBoot 版本

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.6.4</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

Nacos 版本

<dependencies>   
	 ...
	<!--nacos-->
	<dependency>
	    <groupId>com.alibaba.cloud</groupId>
	    <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
	    <version>2.2.6.RELEASE</version>
	</dependency>
</dependencies>

Spring-Cloud 版本

spring-cloud-alibaba依賴,能對(duì)nacos進(jìn)行版本管理

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-alibaba-dependencies</artifactId>
            <version>2.2.6.RELEASE</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-dependencies</artifactId>
            <version>2021.0.1</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

application.yml 配置

  • server-addr:nacos地址
  • namespace:命名空間,即 id
  • group:標(biāo)識(shí)分組
  • file-extension:文件后綴名

spring:
  cloud:
    nacos:
      config:
        server-addr: http://xxx.com
        namespace: name
        group: name
        file-extension: yml

現(xiàn)象

application.yml 配置 myvalue 的值

myvalue: myvalue-test

接口類引用 myvalue

@RestController
@Slf4j
public class TestController extends BaseController {
    @Value("${myvalue}")
    private String myvalue;
    @ApiOperation(value = "測(cè)試", notes = "測(cè)試value")
    @GetMapping(value = "/test/feng/test")
    NjcResponseEntity testValue() {
        log.info( myvalue);
        return super.success("查詢", myvalue);
    }
}

在線修 nacos 上 myvalue 的值

后臺(tái)可以看到 myvalue 已被修改

2023-01-10 10:56:03.402  WARN  [TID: N/A]  c.a.c.n.c.NacosPropertySourceBuilder:  Ignore the empty nacos configuration and get it based on dataId[pm] & group[pm]
2023-01-10 10:56:03.407  WARN  [TID: N/A]  c.a.c.n.c.NacosPropertySourceBuilder:  Ignore the empty nacos configuration and get it based on dataId[pm.yml] & group[pm]
2023-01-10 10:56:03.415  INFO  [TID: N/A]  o.s.c.b.c.PropertySourceBootstrapConfiguration:  Located property source: [BootstrapPropertySource {name='bootstrapProperties-pm-feng.yml,pm'}, BootstrapPropertySource {name='bootstrapProperties-pm.yml,pm'}, BootstrapPropertySource {name='bootstrapProperties-pm,pm'}]
2023-01-10 10:56:03.417  INFO  [TID: N/A]  o.s.boot.SpringApplication:  The following 1 profile is active: "feng"
2023-01-10 10:56:03.425  INFO  [TID: N/A]  o.s.boot.SpringApplication:  Started application in 0.227 seconds (JVM running for 38.127)
Logging initialized using 'class org.apache.ibatis.logging.stdout.StdOutImpl' adapter.
2023-01-10 10:56:03.508  INFO  [TID: N/A]  o.s.c.e.event.RefreshEventListener:  Refresh keys changed: [myvalue]

但通過(guò)接口獲取 myvalue 的值并沒(méi)有改變

優(yōu)化

如何修改為自動(dòng)更新,加上注解 @RefreshScope 即可

@RestController
@Slf4j
@RefreshScope
public class TestController extends BaseController {
    @Value("${myvalue}")
    private String myvalue;
    @ApiOperation(value = "測(cè)試", notes = "測(cè)試value")
    @GetMapping(value = "/test/feng/test")
    NjcResponseEntity testValue() {
        log.info( myvalue);
        return super.success("查詢", myvalue);
    }
}

到此這篇關(guān)于SpringBoot Nacos實(shí)現(xiàn)自動(dòng)刷新的文章就介紹到這了,更多相關(guān)SpringBoot Nacos刷新內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論

晴隆县| 什邡市| 新平| 岳池县| 吴忠市| 罗山县| 尖扎县| 南漳县| 怀远县| 曲水县| 南投县| 勃利县| 邵阳市| 榆社县| 灵寿县| 阿图什市| 炉霍县| 灵山县| 长宁县| 买车| 峡江县| 武强县| 淅川县| 永春县| 扶沟县| 将乐县| 神农架林区| 长岛县| 密山市| 鹰潭市| 天门市| 凌云县| 渭南市| 南召县| 安泽县| 凤翔县| 阳原县| 海宁市| 太保市| 墨脱县| 泸州市|