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;
        }
    }
    
  • 相关阅读:
    程序员书单
    36条极简人生建议
    Nacos
    jvm详解
    22种世界500强都在用的高效工作方法,你了解几种?
    道德经39经典
    积累的力量
    JUC之线程间定制化通信
    JVM调优参考
    docker开机启动和dockercompose开机启动执行相应的各个docker容器
  • 原文地址:https://www.cnblogs.com/sky-chen/p/10189056.html
Copyright © 2011-2022 走看看