SpringBootRibbon负载均衡策略配置
1、前⽂接
2、配置
import comflix.loadbalancer.IRule;
import comflix.loadbalancer.RandomRule;
import org.springframework.boot.SpringApplication;
springframework和springbootimport org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloudflix.eureka.EnableEurekaClient;
import t.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);
}
}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。