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;
        }
    }
    
  • 相关阅读:
    韩信的糊涂
    用友U8两个怪问题
    写给对前途迷茫的朋友:五句话定会改变你的人生
    换博客了
    各种杀毒工具的优缺点
    又是一年中秋到 别有一般更思乡
    谁说黑夜是孤单的
    李想:创业不一定是创办企业
    SQ小组KTV点歌系统简介
    注意!在subList生成子列表之后,一定不要随便更改原列表
  • 原文地址:https://www.cnblogs.com/sky-chen/p/10189056.html
Copyright © 2011-2022 走看看