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;
    }
}
原文地址:https://www.cnblogs.com/sky-chen/p/10189056.html