import com.netflix.loadbalancer.IRule;
import com.netflix.loadbalancer.RandomRule;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;
@SpringBootApplication
@EnableEurekaClient
public class EurekaConsumer_9001 {
@Bean
@LoadBalanced //启用负载均衡机制
public RestTemplate restTemplate() {
return new RestTemplate();
}
@Bean
public IRule ribbonRule() {
//随机负载均衡策略
return new RandomRule();
}
public static void main(String[] args) {
SpringApplication.run(EurekaConsumer_9001.class, args);
}
}
原文:https://www.cnblogs.com/kikyoqiang/p/14674985.html