首页 > 其他 > 详细

Ribbon 配置初步

时间:2019-03-24 19:52:59      阅读:155      评论:0      收藏:0      [点我收藏+]

1.引用pom

     <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-ribbon</artifactId>
            <version>1.4.6.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
            <version>2.1.1.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-config</artifactId>
            <version>2.1.1.RELEASE</version>
        </dependency>

2.修改yml

server:
  port: 80


eureka:
  client:
    register-with-eureka: false
    service-url:
      detaultZone: http://eureka7001.com:7001/eureka/

3.配置类

package com.service.config;

import com.netflix.loadbalancer.IRule;
import com.netflix.loadbalancer.RetryRule;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

@Configuration
public class Dept_Config {

    @Bean
    @LoadBalanced
    public RestTemplate getRestTemplate(){
        return new RestTemplate();
    }

    @Bean
    public IRule myRule(){

        return new RetryRule();
    }
}

 4.启动类

@SpringBootApplication
@EnableEurekaClient
public class Dept_Custor {
    public static void main(String[] args){
        SpringApplication.run(Dept_Custor.class,args);
    }
}

 

Ribbon 配置初步

原文:https://www.cnblogs.com/mm163/p/10589628.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!