修改方式
配置类
- 增加配置类:配置类必须拥有 @Configuration 且不能在 @ComponentScan 包下
代码语言:javascript
复制package com.learning.springcloud.config;
import com.alibaba.cloud.nacos.ribbon.NacosRule;
import com.netflix.loadbalancer.IRule;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class RibbonConfig {
/**
* 全局设置负载均衡策略
*
* @return
*/
@Bean
public IRule iRule() {
return new NacosRule();
}
}
代码语言:javascript
复制package com.learning.springcloud;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.clou