• SpringBoot feign使用


    feign使用三步

    1:引入jar

    2:启动类扫描feign

    3:feign声明

    引入jar如下

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

    启动类扫描

    @EnableFeignClients(basePackages = {"com.feign"})
    

    feign声明

    import org.springframework.cloud.openfeign.FeignClient;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RequestMethod;
    import org.springframework.web.bind.annotation.RequestParam;
    
    import com.ns.common.bean.Response;
    
    @FeignClient(name = "passport",url = "${feign.cunion}")
    public interface PassportFegin {
    
        @RequestMapping(value ="/doctor/patient/searchFuzzy",method = RequestMethod.GET)
        String searchFuzzy(@RequestParam("keyword") String keyword);
    
        @RequestMapping(value ="/doctor/patient/getById",method = RequestMethod.GET)
        Response<Object> getById(@RequestParam("id") String id);
    
    }

    feign header配置

    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
    
    import com.thc.security.util.ThreadLocalUtils;
    
    import feign.RequestInterceptor;
    
    @Configuration
    public class FeignConfig {
    
        @Bean
        public RequestInterceptor requestInterceptor() {
            return requestTemplate -> requestTemplate.header("x-access-token", ThreadLocalUtils.getThreadLocalValue("x-access-token"));
        }
    
    }
    

    配置文件

    feign:
      c-union: http://xxxxxxxx/project

     剩下的就是在业务层注入调用方法即可

  • 相关阅读:
    UVA 11605 Lights inside a 3d Grid
    UVA 10288 Coupons
    UVA 11637 Garbage Remembering Exam
    阿里上市全解读【转载】
    C# 创建系统服务并定时执行【转载】
    Ehcache 整合Spring 使用页面、对象缓存
    详解 Tomcat 的连接数与线程池(转)
    Mysql主从热备
    centos上yum安装异常处理
    tomcat运行模式APR安装
  • 原文地址:https://www.cnblogs.com/zhuxiansheng/p/11246153.html
Copyright © 2020-2023  润新知