1:pom
<!-- nacos-discovery --> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId> </dependency>
2:yml
server: port: 83 spring: application: name: nacos-order-consumer cloud: nacos: discovery: server-addr: 127.0.0.1:8848 # 消费者要访问的微服务名称(注册成功进nacos的微服务提供者) service-url: nacos-user-server: http://nacos-payment-provider
3:启动类
@EnableDiscoveryClient @SpringBootApplication public class OrderMain83 { public static void main(String[] args) { SpringApplication.run(OrderMain83.class); } }
4:RestTemplete
@Component @Configuration public class AppConfiguration { @LoadBalanced // 负载均衡(该注解标记使用哪种负载均衡策略) @Bean public RestTemplate restTemplate() { return new RestTemplate(); } }
分配端口 83