nacos
github地址: https://github.com/alibaba/spring-cloud-alibaba/blob/2.2.x/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/readme-zh.md
一.单机启动方式
方式一: 编辑startup.cmd 修改 set MODE="cluster"为set MODE="standalone"
方式二: startup.cmd -m standalone
二.服务注册与发现
springcloud 2020.0之后用loadbalancer做负载均衡
所以在RestTemplate方法上需要加上@LoadBalanced注解
需要添加loadbalancer依赖
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-loadbalancer</artifactId> <version>3.0.5</version> </dependency>
三.配置中心
增加两个依赖
<dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId> <version>2021.1</version> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-bootstrap</artifactId> <version>3.1.3</version> </dependency>
增加bootstrap.properties配置文件
spring.application.name=nacos-config-client spring.cloud.nacos.discovery.server-addr=localhost:8848 spring.cloud.nacos.config.file-extension=properties