spring cloud Feign使用@RequestLine

如何在微服务项目中调用其它项目的接口试使用spring cloud feign声明式调用。

/**
 * 客户端请去
 * @author RAY
 *
 */
@FeignClient(name="store",configuration=FooConfiguration .class)
public interface UserFeignClient {
    
    
    @RequestLine("GET /simple/{id}")
    public  User findById(@Param("id") Long id);
}

但是启动得时候报错: 
 

Method getLinksForTrack not annotated with HTTP method type (ex. GET, POST)

官方文档说明

@RequestLine is a core Feign annotation, but you are using the Spring Cloud @FeignClientwhich uses Spring MVC annotations. 

意思就是feign 默认使用的是spring mvc 注解(就是RequestMapping 之类的) ,所以需要通过新增一个配置类来修改其“契约”。

@Configuration
public class FooConfiguration {
    @Bean
    public Contract feignContract() {
        return new feign.Contract.Default();
//使用feign自带契约
    }

}

PS :  feignContract方法名不要跟一样。否则启动得时候会报错。 得改一个跟类名不一样得方法名!

完!!!!

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值