我们的服务提供者很对时候会配置server.servlet.context-path此时我们按照之前的feign配置去请求服务提供者的话会报404,无法找到请求路径。
我们在@FeignClient的请求路径上添加根路径信息(有时会报错):
@FeignClient(name = "test1",configuration = FeignClientsConfiguration.class)
public interface FeignTest1Service {
@RequestMapping(value = "/eureka-clinet1/ribbonTest",method = RequestMethod.POST)
public String testFeign(@RequestBody Map<String,String> map);
}
我们可以在@FeignClient上配置path属性,设置根路径【推荐设置这个】
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.cloud.openfeign.FeignClientsConfiguration;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import java.util.Map;
@FeignClient(name = "test1",path ="eureka-clinet1",configuration = FeignClientsConfiguration.class)
public interface FeignTest1Service {
@RequestMapping(value = "/ribbonTest",method = RequestMethod.POST)
public String testFeign(@RequestBody Map<String,String> map);
}
运行: