Nacos Getting Started Guide|Still using eureka, come and learn about nacos

1. How to use nacos as a configuration center for unified management configuration

  • Download and install nacos
    1. Download link: Resource download
    2. Installation: After decompression, click start.cmd to start directly, visit http://localhost:8848
  • Introduce dependencies
        <!--        配置中心来做配置管理-->
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
        </dependency>
  • Create a bootstrap.properties file
spring.application.name=lezaimall-coupon
spring.cloud.nacos.config.server-addr=127.0.0.1:8848
  • Add a data set (DataId) lezaimall-coupon.properties, default rule, application name.properties in the configuration center
  • Edit configuration file
  • Dynamically obtain configuration
在需要使用@Value的注解的类上面,都加上@RefreshScope注解,如果配置中和应用中都是用了相同的配置,则优先使用配置中心的配置

2. Details

Namespace: configuration isolation

默认:public(保留空间);默认新增的所有的配置都在public空间
1.开发,测试,生产:利用命名空间来做环境隔离
	注意:在bootstrap.properties上,如何配置使用指定的命名空间?
	spring.cloud.nacos.config.namespace=命名空间ID
2.每一个微服务之间相互隔离配置,每个微服务拥有自己的命名空间,只加载自己命名空间下的配置

Arrangement collection

The collection of all configurations is called a configuration set

Arrangement collection ID

data_id: configuration file name

Configuration group

By default, all configurations belong to:
How to configure DEFAULT_GROUP to the specified group?
spring.cloud.nacos.config.group=group name

Configure multiple data sets

spring.cloud.nacos.config.namespace=88b42d3d-d10b-44f9-a987-dacce6278fe3 #Specify the namespace
spring.cloud.nacos.config.ext-config[0].data-id=application.yml # Specify the first one Configuration file name
spring.cloud.nacos.config.ext-config[0].group=dev # Specify the group name of the first configuration file
spring.cloud.nacos.config.ext-config[0].refresh=true
#The default extension does not automatically refresh, you need to set the automatic refresh spring.cloud.nacos.config.ext-config[1].data-id=mybatis.yml # Specify the second configuration file name
spring.cloud.nacos.config.ext -config[1].group=dev# Specify the group to which the second configuration file belongs
spring.cloud.nacos.config.ext-config[1].refresh=true# Specify the automatic refresh of the second configuration file

Guess you like

Origin blog.csdn.net/weixin_34311210/article/details/106206694