zoukankan      html  css  js  c++  java
  • Nacos 动态配置

    1、安装nacos

    2、Spring cloud工程中引入依赖

            <!--nacos客户端-->
            <dependency>
                <groupId>com.alibaba.cloud</groupId>
                <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
            </dependency>
    
    
            <dependency>
                <groupId>com.alibaba.cloud</groupId>
                <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
            </dependency>
    

      

    3、创建命名空间

    分别为dev 和 test

    创建配置

     例如interfaces-dev.yml

    4、服务配置

    服务使用的版本信息  Spring Cloud:Greenwich.RELEASE, Spring Boot 2.1.3; Spring Cloud Alibaba: 2.1.2.RELEASE

    1) bootstrap.yml

    2) PropertiesConfig.java

    @Data
    @RefreshScope
    @ConfigurationProperties(prefix = "dynamic.interfaces")
    public class PropertiesConfig {
    
        private String info = "动态信息";
    }
    

      

    3) 增加注解EnableConfigurationProperties

    4) 测试

        @Autowired
        PropertiesConfig propertiesConfig;
    
        @RequestMapping("/say")
        public String sayHello() {
            return propertiesConfig.getInfo();
    
        }  

    调用接口后返回

    5、修改interfaces-dev.yml,返回发布

    发布成功后,工程将收到消息,刷新配置信息。

    再次调用接口,可以发现内容已经修改过了,从而实现了动态属性的修改。

     参考: https://nacos.io/zh-cn/docs/quick-start-spring-cloud.html

  • 相关阅读:
    Vue 02
    Vue 初识
    复杂数据类型之函数 对象
    Collections工具类
    遍历集合的方法总结
    使用Iterator迭代器遍历容器元素(List/Set/Map)
    TreeSet的使用和底层实现
    HashSet基本使用
    HashSet底层实现
    TreeMap的使用和底层实现
  • 原文地址:https://www.cnblogs.com/linlf03/p/14177748.html
Copyright © 2011-2022 走看看