nacos服务配置中心演示

config center

    • Nacos作为配置中心-基础配置
    • Nacos作为配置中心-分类配置
    • nacos将配置持久化到mysql

新型技术,替代spring config center & bus

Nacos作为配置中心-基础配置

⑴ module
cloudalibaba-config-nacos-client3377

(2) pom

 <dependencies><!--nacos-config--><dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId></dependency><!--nacos-discovery--><dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId></dependency><!--web + actuator--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId></dependency><!--一般基础配置--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-devtools</artifactId><scope>runtime</scope><optional>true</optional></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><optional>true</optional></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency></dependencies>

(3) yaml

  • application.yaml
# environmentspring:profiles:# active: dev# active: testactive: info # 测试分组
  • bootstrap.yaml
# config center --> serverserver:port: 3377spring:application:name: nacos-config-clientcloud:nacos:discovery:server-addr: localhost:8848 #服务注册中心地址config:server-addr: localhost:8848 #配置中心地址file-extension: yaml #指定yaml格式的配置# group: DEV_GROUP # 生产 分组group: TEST_GROUP # 测试 分组namespace: ac4eb07f-e257-44eb-80fb-178447a304f7 # 配置namespace 为流水号, 下面可以有多个分组group, 每个分组可以有多个实例dataId# 配置规则如下.# https://nacos.io/zh-cn/docs/quick-start-spring-cloud.html
# ${prefix}-${spring.profiles.active}.${file-extension}
# {spring.application.name}-${profile}.${spring.cloud.nacos.config.file-extension}
# so dataID ---> nacos-config-client-dev.yaml

(4) 主启动

@EnableDiscoveryClient
@SpringBootApplication
public class NacosConfigClientMain3377 {public static void main(String[] args) {// bootSpringApplication.run(NacosConfigClientMain3377.class, args);}}

(5) 业务接口,配置刷新

@RefreshScope // auto refresh config
@RestController
public class ConfigClientController {@Value("${config.info}")private String configInfo;@GetMapping("/config/info")public String getConfigInfo() {return "config info from nacos center ---> \n" + configInfo;}}

(6)核心,在nacos web界面配置信息存放


界面配置
在这里插入图片描述

(7)配置搞定后,启动服务,访问接口,便可获取配置信息了。

Nacos作为配置中心-分类配置

nacos 中的namespace, group, dataId. 类似Java中的包,类,方法。

  • dataId, 指定spring.profile.active和配置文件的DataID来使不同环境下读取不同的配置. 切换application.yaml 中的环境即可。
  • group方案,新建分组即可,通过group来区分环境。
  • namespace方案,区分环境。

nacos将配置持久化到mysql

默认持久化到内置数据库derby
https://nacos.io/zh-cn/docs/deployment.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/420424.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

前端学习(1296):第三方模块nodemon

修改保存重新执行 如何断开ctrlc

core java 8~9(GUI AWT事件处理机制)

MODULE 8 GUIs--------------------------------GUI中的包&#xff1a; java.awt.*; javax.swing.*; java.awt.event.*; 要求:1)了解GUI的开发流程&#xff1b;2&#xff09;掌握常用的布局管理器 开发GUI图形界面的步骤-------------------------------1.选择容器 1&#xff0…

note.. redis五大数据类型

redis 五大数据类型使用nosql介绍&#xff0c;由来什么是nosql阿里巴巴的架构nosql 四大分类redis入门概述redis 安装 &#xff08;docker&#xff09;基础的知识redis五大数据类型Redis-KeyStringList (列表)Set &#xff08;集合&#xff09;Hash(哈希)Zset 有序集合nosql介绍…

Arcengine 基本操作(待更新)

/// <summary>/// 删除fieldName属性值为1的弧段/// </summary>/// <param name"fieldName"></param>/// <param name"t"></param>public void DelectPolyline(string fieldName, int t){ILayer pLayer axMapControl…

redis 三种特殊数据类型

三种特性数据类型 geospatial 定位&#xff0c;附近的人&#xff0c;打车距离计算。 redis的geo在redis3.2版本就推出了。可推算地理位置的信息&#xff0c;两地之间的距离&#xff0c;方圆几里的人。 6个命令。 GEOADD GEODIST GEOHASH GEOPOS GEORADIUS GEORADIUSBYMEMB…

前端学习(1298):gulp使用

第一步安装 第二步建立文件夹 第三部 src放源代码 第四步 输入代码 执行

Sentinel 分布式系统的流量防卫兵

sentinelsentinel base服务编写关键名词解释sentinel base 官网&#xff1a; https://github.com/alibaba/Sentinel https://github.com/alibaba/Sentinel/wiki/%E4%BB%8B%E7%BB%8D 是什么&#xff1f; 是一款优秀的限流&#xff0c;降级&#xff0c;熔断的框架。 Sentinel …

php查询mysql返回大量数据结果集导致内存溢出的解决方法

web开发中如果遇到php查询mysql返回大量数据导致内存溢出、或者内存不够用的情况那就需要看下MySQL C API的关联,那么究竟是什么导致php查询mysql返回大量数据时内存不够用情况&#xff1f; 答案是: mysql_query 和 mysql_unbuffered_query 两个函数 首先来分析一个典型的实例:…

前端学习(1299):gulp插件

第一步 下载 第二步 const gulp require(gulp); const htmlmin require(gulp-htmlmin);gulp.task(first, () > {console.log(第一次执行);}); gulp.task(htmlmin, () > {gulp.src(./src/*.html)//压缩去其中的代码.pipe(htmlmin({ collapseWhitespace: true })).pipe(…

前端学习(1300)报错:无法加载文件 D:\nodejs\node_global\webpack.ps1,因为在此系统上禁止运行脚本...

解决报错&#xff1a; &#xff08;1&#xff09;以管理员身份运行命令行设置即可 &#xff08;2&#xff09;在终端执行&#xff1a;get-ExecutionPolicy&#xff0c;显示Restricted&#xff08;表示状态是禁止的&#xff09; &#xff08;3&#xff09;在终端执行&#xff…

动态规划系列 | 最长上升子序列模型(上)

文章目录 最长上升子序列回顾题目描述问题分析程序代码复杂度分析 怪盗基德的滑翔翼题目描述输入格式输出格式 问题分析程序代码复杂度分析 登山题目描述输入格式输出格式 问题分析程序代码复杂度分析 合唱队形题目描述输入格式输出格式 问题分析程序代码复杂度分析 友好城市题…

docker 安装部署nacos

docker 安装nacospull镜像配置mysql挂载运行单机nacos部署。考虑到nacos比较耗费性能&#xff0c;使用docker部署学习。 pull镜像 1.3.1 是github上说明的稳定版本. 至少现在是。 docker pull nacos/nacos-server:1.3.1配置mysql 1. mysql创建nacos_config 数据库2. 数据sq…

ASP.NET(c#)实现重定向的三种方法的总结

(1)Server.Transfer方法: Server.Transfer("m2.aspx");//页面转向(服务器上执行). 服务器停止解析本页,保存此页转向前的数据后,再使页面转向到m2.aspx, 并将转向前数据加上m2.aspx页结果返回给浏览器. (2)Server.Execute方法: Server.Execute("m2.aspx")…

前端学习(1301):gulp建立任务csso和less

const gulp require(gulp); const htmlmin require(gulp-htmlmin); const fileinclude require(gulp-file-include); const less require(gulp-less); gulp.task(first, () > {console.log(第一次执行);});gulp.task(htmlmin, () > {gulp.src(./src/*.html)//压缩去其…

just for rest~

整理了一些可以放昵称的可爱符号&#xff01;ᑋᵉᑊᑊᵒ ᵕ̈ ᑋᵉᑊᑊᵒഒ˙˙₍ᐢ..ᐢ₎˙Ⱉ˙(⌓) ִִ•ᴥ•ଲॱଳॱ————————————ꙫ˙Ꙫ˙&#xff65;◡&#xff65;꒦ິ^꒦ິ•́‸กᵕ᷄≀ ̠˘᷅- ̗̀(ᵔ⌔ᵔ)˙Ⱉ˙˃̶͈ ˂̶͈՞• •՞˙Ⱉ˙҉ง⍢⃝

前端学习(1302):实现es6的转化

const gulp require(gulp); const htmlmin require(gulp-htmlmin); const fileinclude require(gulp-file-include); const less require(gulp-less); const csso require(gulp-csso); const babel require(gulp-babel); gulp.task(first, () > {console.log(第一次执…

EF6 如何判断DataContext有修改,以及如何放弃修改

如何判断DataContext有修改&#xff1a; EF6的 using (var db new Model1()) {if (db.ChangeTracker.HasChanges()){Console.WriteLine("Something has changed");} } EF5中&#xff1a; public bool HasUnsavedChanges(){return this.ChangeTracker.Entries().Any(…

boot整合redis

redisTemplate封装pomredisTemplate配置类redis工具类封装pom <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-redis</artifactId></dependency>redisTemplate配置类 覆盖默认的redis模板…