zoukankan      html  css  js  c++  java
  • 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

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

  • 相关阅读:
    重点解说--MVVM指南(课程学习)
    模块划分--MVVM指南(课程学习)
    开发步骤--MVVM指南(课程学习)
    MVVM指南(课程学习)
    centos vi和vim用法
    阿里云centos系统上安装ftp
    thinkphp的ip地址定位
    thinkphp方便分页的page方法
    thinkphp data方法
    thinkphp i方法
  • 原文地址:https://www.cnblogs.com/zhuxiansheng/p/11246153.html
Copyright © 2011-2022 走看看