Nacos
该文档主要针对nacos的配置中心功能,演示springBoot、springCloud集成nacos
Nacos是什么
Nacos 支持基于 DNS 和基于 RPC 的服务发现(可以作为springcloud的注册中心)、动态配置服务(可以做配置中心)、动态 DNS 服务。
Nacos名词概念
NameSpace:针对不同环境定义不同命名空间如果不指定,则默认使用public
命名空间,如需指定命名空间,需要在配置文件中提前配置。
Data Id:可以理解为配置文件名,是nacos配置中心中最小粒度,使用Data Id可以定位到一个配置文件
Group:分组名,使用dataId+group可以定位到一个配置文件,如不指定group则默认使用DEFAULT_GROUP
,如需要指定分组,需要在配置文件中提前配置
Nacos的配置中心功能怎么用
nacos环境搭建
- 找运维
SpringBoot集成Nacos
-
相关依赖
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <parent> <artifactId>nacos-examples</artifactId> <groupId>com.alibaba.nacos</groupId> <version>0.2.0-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>nacos-spring-boot-example</artifactId> <packaging>pom</packaging> <modules> <module>nacos-spring-boot-config-example</module> <module>nacos-spring-boot-config-mysql-example</module> <module>nacos-spring-boot-discovery-example</module> </modules> <properties> <spring-boot.version>2.0.3.RELEASE</spring-boot.version> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion> </properties> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-dependencies</artifactId> <version>${spring-boot.version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> </project>
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.