• 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;
        }
    }
    
  • 相关阅读:
    绑定class -vue
    二叉树按层打印,并且按层换行的方法
    curl相关知识
    python创建简单的http服务器
    有关rides数据库的想法
    java模拟实现有序表操作
    php静态方法
    php关闭浏览器不终止运行
    php读取图片以二进制输出
    借用face++人脸识别,来识别年龄
  • 原文地址:https://www.cnblogs.com/sky-chen/p/10189056.html
Copyright © 2020-2023  润新知