前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >feign包名路径添加问题

feign包名路径添加问题

作者头像
老梁
发布2019-09-10 18:10:52
9230
发布2019-09-10 18:10:52
举报

1. feign包名路径添加问题

1.1. 问题

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

1.2. 解决方式

  1. 添加path
代码语言:javascript
复制
@FeignClient(path = "/hospital-auth",value = "hospital-auth", fallback = HospitalFallBack.class, configuration = FeignMultipartSupportConfig.class)

1.3. 完整代码实例

代码语言:javascript
复制
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;
    }
}
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2018-12-28 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 1. feign包名路径添加问题
    • 1.1. 问题
      • 1.2. 解决方式
        • 1.3. 完整代码实例
        领券
        问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档