zoukankan      html  css  js  c++  java
  • springBoot Feign

    1.引入依赖包

    <!-- 引入关于 eureka-server的依赖 -->
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
                <version>2.0.2.RELEASE</version>
            </dependency>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-openfeign</artifactId>
                <version>2.0.2.RELEASE</version>
            </dependency>

    2.主函数

    @EnableEurekaClient
    @EnableFeignClients

    3.创建feign配置文件

    package com.example.eurekafeignclient.config;
    
    import feign.Retryer;
    import org.springframework.context.annotation.Configuration;
    
    import java.util.concurrent.TimeUnit;
    
    
    @Configuration
    public class feignConfig {
        public Retryer feignRetryer() {
            return new Retryer.Default(100, TimeUnit.SECONDS.toMillis(1), 5);
        }
    }//end

    4.创建接口

    package com.example.eurekafeignclient;
    
    import com.example.eurekafeignclient.config.feignConfig;
    import org.springframework.cloud.openfeign.FeignClient;
    import org.springframework.stereotype.Service;
    import org.springframework.web.bind.annotation.GetMapping;
    
    
    @FeignClient(value = "eureka-client", configuration = feignConfig.class)
    @Service
    public interface imp_eurekaClientFeign {
        @GetMapping(value = "/hello")
        String hello11();
    }//end

    5.创建controller调用

    package com.example.eurekafeignclient.controller;
    
    import com.example.eurekafeignclient.imp_eurekaClientFeign;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RestController;
    
    @RestController
    public class clientController {
        @Autowired
        imp_eurekaClientFeign imp_eurekaClientFeign_;
        @RequestMapping("/hello")
        public String hello() {
            return imp_eurekaClientFeign_.hello11();
        }
    }
    欢迎指正:haizi2014@qq.com
  • 相关阅读:
    组合总和
    子集Ⅱ
    子集
    全排列Ⅱ
    全排列
    填充下一个结点下一个Next结点
    把二叉树转化成累加树
    二叉树的左叶子之和
    高速C/C++编译工具ccache
    【转载】如何用U盘制作Ubuntu启动盘
  • 原文地址:https://www.cnblogs.com/hcfan/p/10151315.html
Copyright © 2011-2022 走看看