当前位置:网站首页>[Microservice~Nacos] Configuration Center of Nacos
[Microservice~Nacos] Configuration Center of Nacos
2022-07-30 01:24:00 【Books of Coriander】
??这里是【微服务~Nacos】,关注我学习云原生不迷路
??如果对你有帮助,给博主一个免费的点赞以示鼓励
欢迎各位??点赞??评论收藏
??专栏介绍
【微服务~Nacos】 目前主要更新微服务,一起学习一起进步.
??本期介绍
本期主要介绍微服务~Nacos
文章目录
搭建服务
- 项目名:nacos-config-2.1
添加坐标:

<dependencies>
<!-- web 启动器 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- nacos 服务发现 -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<!-- nacos 配置-->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency>
</dependencies>
- 创建yml配置文件:bootstrap.yml

server:
port: 8072 # 端口号
spring:
application:
name: config-service # 服务名
cloud:
nacos:
config:
server-addr: 127.0.0.1:8848 # nacos 服务地址
prefix: ${spring.application.name} #data ID的前缀,默认服务名
file-extension: yaml # data ID的后缀:config-service.yaml
group: DEFAULT_GROUP # 组名
discovery:
server-addr: 127.0.0.1:8848 #nacos服务地址
创建服务
- 编写启动类

package com.czxy.nacos;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class TestNacosCloudConfigApplication {
public static void main(String[] args) {
SpringApplication.run(TestNacosCloudConfigApplication.class, args);
}
}
- 编写处理类

package com.czxy.nacos.controller;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/config")
@RefreshScope
public class ConfigController {
@Value("${czxy.message:'默认值'}")
private String msg;
/**
* http://localhost:8072/config/get
*/
@RequestMapping("/get")
public String get() {
return msg;
}
}
查询服务
- 情况1,访问“默认数据”
http://localhost:8072/config/get

情况2,访问yml文件配置信息
czxy:
message: 测试数据

- 情况3:访问nacos中的配置数据


整合知多少
- 在 Nacos Spring Cloud 中,
dataId的完整格式如下
p r e f i x − {prefix}- prefix−{spring.profile.active}.${file-extension}
显示profile中的数据
- 1)编写profile:application-demo.yml

server:
port: 8073 # 端口号
czxy:
message: demo数据
2)修改启动项
-Dspring.profiles.active=demo

3)删除nacos配置后,测试

nacos 默认配置
- 1)nacos配置
config-service.yaml的 Data ID

2)测试

nacos 配置 profile
- 1)配置nacos profile :
config-service-demo.yaml

2)测试

nacos配置文件加载顺序
spring boot、nacos各种配置文件的加载顺序
1.bootstrap.yml
2.application.yml
3.application-[profile].yml
4.[serviceName].yml #nacos配置
5.[serviceName]-[profile].yml #nacos配置
- 后面加载的文件,将覆盖前面文件的配置内容
先自我介绍一下,小编13年上师交大毕业,曾经在小公司待过,去过华为OPPO等大厂,18年进入阿里,直到现在.深知大多数初中级java工程师,想要升技能,往往是需要自己摸索成长或是报班学习,但对于培训机构动则近万元的学费,着实压力不小.自己不成体系的自学效率很低又漫长,而且容易碰到天花板技术停止不前.因此我收集了一份《java开发全套学习资料》送给大家,初衷也很简单,就是希望帮助到想自学又不知道该从何学起的朋友,同时减轻大家的负担.添加下方名片,即可获取全套学习资料哦
边栏推荐
猜你喜欢

把@Transactional事务注解用到如此炉火纯青,真的强!

Navicat for mysql crack version installation

【LeetCode每日一题】——404.左叶子之和

nacos集群配置详解
![[Training DAY16] ALFA [convex hull] [computational geometry]](/img/26/ecc77dabdf468b3a8ad3888b292496.png)
[Training DAY16] ALFA [convex hull] [computational geometry]

推荐系统:用户“行为数据”的采集【使用Kafaka、Cassandra处理数据】【如果与业务数据重合,也需要独自采集】

Recommendation systems: feature engineering, common features

go语言解决自定义header的跨域问题

Towards Better Understanding of Self-Supervised Representations / Q-Score

9 common mistakes testers fall into
随机推荐
泰克Tektronix示波器软件TDS1012|TDS2002|TDS2004上位机软件NS-Scope
MySQL高级篇(高阳)建表sql语句大全
不要急,没有一朵花,从一开始就是花,也不要嚣张,没有一朵花,
sqlserver 多行合并成一行
LABVIEW详细介绍:LABVIEW是什么软件?都可以干什么?
Recommendation system: collection of user "behavioral data" [use Kafka and Cassandra to process data] [if it overlaps with business data, it also needs to be collected independently]
Detailed introduction to the usage of Nacos configuration center
解决vscode的Network不显示问题
Missing X64 mfc140u. DLL file - > application cannot normal boot (0 xc000007b) solution
泰克Tektronix示波器软件TDS210|TDS220|TDS224上位机软件NS-Scope
npm ERR! code ENOTSUP npm ERR! notsup Unsupported engine for [email protected]: wanted: {“n
Baidu Intelligent Cloud Zhangmiao: Detailed explanation of enterprise-level seven-layer load balancing open source software BFE
How Filebeat ensures that the log file is still correctly read when the log file is split (or rolled)
Navicat for mysql crack version installation
【微服务~Nacos】Nacos之配置中心
基于SSM开发实现校园疫情防控管理系统
新型LaaS协议Elephant Swap给ePLATO提供可持续溢价空间
7.28
SSM整合案例
Elephant Swap:借助ePLATO提供加密市场的套利空间