当前位置: 首页 > article >正文

【SpringCloud】05-配置中心

1. 配置管理

在这里插入图片描述
在这里插入图片描述
实现配置管理热更新。

2. 配置编写

在这里插入图片描述
在这里插入图片描述

3. 微服务拉取Nacos配置

在这里插入图片描述

  1. 引入加载bootstrap.yaml的依赖。
  <!--nacos配置管理-->
  <dependency>
      <groupId>com.alibaba.cloud</groupId>
      <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
  </dependency>
  <!--读取bootstrap文件-->
  <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-bootstrap</artifactId>
  </dependency>
  1. bootstrap.yaml
spring:
  application:
    name: cart-service
  profiles:
    active: dev
  cloud:
    nacos:
      server-addr: 139.224.66.95:8848
      config:
        file-extension: yaml
        shared-configs:
          - data-id: shared-jdbc.yaml
          - data-id: shared-log.yaml
          - data-id: shared-swagger.yaml
  1. application.yaml
server:
  port: 8084
feign:
  okhttp:
    enabled: true # 开启OKHttp功能
hm:
  db:
    host: localhost
    database: hm-cart
  swagger:
    title: "购物车管理接口"
    package: com.hmall.cart.controller

4. 配置热更新

当修改配置文件中的配置时,微服务无需重启即可使配置生效。

  1. 配置类
@Data
@Component
@ConfigurationProperties(prefix = "hm.cart")
public class CartProperties {
    private Integer maxItems;
}
  1. nacos配置文件
    在这里插入图片描述

http://www.kler.cn/news/360093.html

相关文章:

  • 微信小程序——消息订阅
  • Spring Boot项目中怎么设置内容安全策略Content Security Policy
  • C++题集
  • ICRA@40 周年大会:多指手既可抓取,又可以变成多足机器人
  • [openwrt-21.02]openwrt-21.02 增加固件编译日期时间及git记录到openwrt_release文件
  • 【微信小程序_15_下拉刷新与上拉触底】
  • JavaScript中实现十进制转二进制算法
  • 1020接口测试面试题随记
  • golang的数组、slice和map
  • 【专题】数据库编程
  • 人工智能技术的应用前景及其对生活和工作方式的影响
  • sql server 行转列及列转行
  • 程序设计基础I-单元测试2(机测)
  • 华为eNSP Destination host unreachable和Request timeout!错误(详细解析)
  • 【无标题】如何使用yolo-v8 实现自定义目标检测
  • 教学平台的信息化之路:Spring Boot实践
  • 【ChatGPT】提高 ChatGPT 创意输出的提示词技巧
  • 在windows下利用安装docker加vscode调试OceanBase,
  • Pandas | 通过PUBG数据集进行数据分析并理解函数使用
  • 鸿蒙网络编程系列22-Web组件文件上传示例