排错feign.FeignException$NotFound: [404]

完整错误如下
feign.FeignException$NotFound: [404] during [GET] to [http://microservice-provider-user/] [UserFeignService#findById(int)]: [{“timestamp”:“2021-04-29T03:02:57.063+00:00”,“status”:404,“error”:“Not Found”,“message”:“No message available”,“path”:"/"}]

配置类

public class FeginConfiguration {
	
	@Bean
	public Contract getContract() {
		return new feign.Contract.Default();
	}

}

Feign服务接口类

@FeignClient(name="microservice-provider-user",configuration = FeginConfiguration.class)
public interface UserFeignService {
	
	@RequestLine("GET /{id}")
	public User findById(@PathVariable("id") int id);
}

将Feign服务修改如下再次访问测试成功。

import feign.Param;
import feign.RequestLine;

@FeignClient(name="microservice-provider-user",configuration = FeginConfiguration.class)
public interface UserFeignService {
	
	@RequestLine("GET /{id}")
	public User findById(@Param("id") int id);
}

修改的内容为将spring web包下的注解PathVariable换成了feign core包下的Param.

分析如下,如果使用PathVariable,那么controller传过来的id,就无法传递给feign的注解RequestLine.
那么Fegin最终组装的URL就是Get请求的http://microservice-provider-user/,因为id无法传递给RequestLine, 那么/{id},就会解析成 / .
这里Param和RequestLine需要配套使用

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值