RestConfig.java 634 字节
Newer Older
Q
qinyingjie 已提交
1 2
package com.kwan.springcloud.config;

Q
qinyingjie 已提交
3 4
import com.netflix.loadbalancer.IRule;
import com.netflix.loadbalancer.RandomRule;
Q
qinyingjie 已提交
5
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
Q
qinyingjie 已提交
6 7 8 9 10 11 12
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

@Configuration
public class RestConfig {

Q
qinyingjie 已提交
13
    @LoadBalanced
Q
qinyingjie 已提交
14 15 16 17
    @Bean
    public RestTemplate restTemplate() {
        return new RestTemplate();
    }
Q
qinyingjie 已提交
18 19 20 21 22 23 24 25 26

    /**
     * 自定义负载均衡
     */
    @Bean
    public IRule microIrule() {
        return new RandomRule();
    }
}