spring cloud alibaba 整合 Ribbon

restTemplate 整合 Ribbon

// 在spring 容器中创建  类型是 RestTemplate  名称:/ID restTemplate
@Bean
// 引入Ribbon RestTemplate整合Ribbon
@LoadBalanced
public RestTemplate restTemplate(){
    return new RestTemplate();
}

代码方式配置

package com.zhunedu.smartcampus.configuration;
/**
 * @author : liwei
 * create at:  2019-08-15  15:07
 * @description: OA服务负载均衡
 */
@Configuration
@RibbonClient(name = "user-center",configuration = RibbonConfiguration.class)
public class OaServicesRibbonConfigration {
}
package ribbonconfigration;
/**
 * @author : liwei
 * create at:  2019-08-15  15:09
 * @description: 负载均衡
 */
@Configuration
public class RibbonConfiguration {

    @Bean
    public IRule ribbonRule(){
        return new RandomRule();
    }
}

属性方式配置

## 负载均衡配置
#user-center:
#  ribbon:
#    # 负载均衡策略
#    NFLoadBalancerRuleClassName: com.netflix.loadbalancer.RandomRule

你可能感兴趣的:(springcloud,alibaba)