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

SpringBoot Nacos實現(xiàn)自動刷新

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

背景

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依賴,能對nacos進行版本管理

<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:標識分組
  • 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 = "測試", notes = "測試value")
    @GetMapping(value = "/test/feng/test")
    NjcResponseEntity testValue() {
        log.info( myvalue);
        return super.success("查詢", myvalue);
    }
}

在線修 nacos 上 myvalue 的值

后臺可以看到 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]

但通過接口獲取 myvalue 的值并沒有改變

優(yōu)化

如何修改為自動更新,加上注解 @RefreshScope 即可

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

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

相關(guān)文章

最新評論

右玉县| 江都市| 迭部县| 定襄县| 兴和县| 乐亭县| 开阳县| 新郑市| 远安县| 东台市| 梅河口市| 邓州市| 高邮市| 银川市| 自治县| 桂林市| 烟台市| 永昌县| 荣昌县| 汶上县| 新闻| 山东省| 弋阳县| 龙里县| 五常市| 鹰潭市| 汨罗市| 贵定县| 台东市| 宜州市| 道真| 肇东市| 天门市| 剑阁县| 兴海县| 吉林省| 开封市| 佛山市| 胶南市| 蒙阴县| 泰顺县|