1.Nacos
I have used the eureka registration center of spring cloud before, and the configuration is a bit cumbersome; nacos is a component developed by Ali that provides registration center and configuration center functions, and the operation is much simpler
1.1 Nacos download
startup.cmd -m standalone
close command
shutdown.cmd
1.2 Nacos Registration Center
Import the Nacos Service Discovery dependency when creating a project. The Nacos configuration class will be automatically generated under the project. If it is not generated, you need to add the annotation @EnableDiscoveryClient to the main startup class
Configure the main configuration
server:
port: 8081
spring:
application:
name: goods
cloud:
nacos:
discovery:
server-addr: 192.168.74.146:8848
Start the microservice, open localhost:8848/nacos, if there is the microservice in the service after login, the configuration is successful
1.3 Nacos Configuration Center
First clear the content in the main configuration file that comes with it
Then create a new bootstrap.yml configuration file (this configuration file is before the traditional configuration file and has a higher priority)
spring:
cloud:
nacos:
discovery:
server-addr: 192.168.5.225:8848
username: nacos
password: nacos
config:
file-extension: yaml #yaml就是yml 要获取配置信息的后缀名
group: wuye
namespace: 330d5266-2f60-48ed-b215-1cb2359d6843 #命名空间id
profiles:
active: dev #获取哪个环境的配置信息 dev:开发、test:测试、pro:生产
application:
name: user
#user-dev.yaml 配置文件名(官方规定格式)
Then configure it in the nacos webpage
Start the microservice and the configuration is successful
[Different projects can be configured with different groups]