zoukankan      html  css  js  c++  java
  • feign包名路径添加问题

    1. feign包名路径添加问题

    1.1. 问题

    在SpringCloud中使用feign调用路径中,不能在类上直接添加@RequestMapping(value = "/hospital-auth")作为公共路径
    

    1.2. 解决方式

    1. 添加path
    @FeignClient(path = "/hospital-auth",value = "hospital-auth", fallback = HospitalFallBack.class, configuration = FeignMultipartSupportConfig.class)
    

    1.3. 完整代码实例

    package com.zhiyis.framework.service.remote.feign;
    
    import com.zhiyis.common.report.ResponseReport;
    import com.zhiyis.framework.service.remote.config.FeignMultipartSupportConfig;
    import org.springframework.cloud.netflix.feign.FeignClient;
    import org.springframework.http.MediaType;
    import org.springframework.stereotype.Component;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RequestParam;
    import org.springframework.web.bind.annotation.RequestPart;
    import org.springframework.web.multipart.MultipartFile;
    
    /**
     * @author laoliangliang
     * @date 2018/11/2 13:55
     */
    @FeignClient(path = "/hospital-auth",value = "hospital-auth", fallback = HospitalFallBack.class, configuration = FeignMultipartSupportConfig.class)
    public interface HospitalFeign {
    
        @RequestMapping(value = "/rpc.api", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
        ResponseReport doRemoteCall(@RequestParam(value = "report", required = false) String report, @RequestPart(value = "file", required = false) MultipartFile multipartFile);
    
        @RequestMapping(value = "/rpc.api")
        ResponseReport doRemoteCall(@RequestParam(value = "report", required = false) String report);
    
    }
    
    @Component
    class HospitalFallBack implements HospitalFeign {
    
        @Override
        public ResponseReport doRemoteCall(String report, MultipartFile multipartFile) {
            ResponseReport responseReport = new ResponseReport();
            responseReport.returnError("9999", "HospitalFeign 医院服务调用失败");
            return responseReport;
        }
    
        @Override
        public ResponseReport doRemoteCall(String report) {
            ResponseReport responseReport = new ResponseReport();
            responseReport.returnError("9999", "HospitalFeign 医院服务调用失败");
            return responseReport;
        }
    }
    
  • 相关阅读:
    go1.13 mod 实践和常见问题
    etcd 添加用户,授权特定目录
    golang 你所不知道的 log 和 fmt
    redis 原理系列之--字符串存储的实现原理(1)
    golang 写文件--详细解释
    面向对象范式的核心本质是?---不是继承 不是封装也不是多态
    关于自控力和拖延 的一点分享--《自控力》
    Linux 精确判断是否同一文件--及终端获取字符串md5 的值
    ARM版本及系列
    技术团队塑造
  • 原文地址:https://www.cnblogs.com/sky-chen/p/10189056.html
Copyright © 2011-2022 走看看